Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> successful steps, if * the step is rejected after the error estimation phase, no * evaluation is saved. For an <i>fsal</i> method, we have cs = 1 and * asi = bi for all i.</p> * * @version $Revision$ $Date$ * @since 1.2 */ public abstract class EmbeddedRungeKuttaIntegrator extends AdaptiveStepsizeIntegrator { /** Indicator for <i>fsal</i> methods. */ private final boolean fsal; /** Time steps from Butcher array (without the first zero). */ private final double[] c; /** Internal weights from Butcher array (without the first empty row). */ private final double[][] a; /** External weights for the high order method from Butcher array. */ private final double[] b; /** Prototype of the step interpolator. */ private final RungeKuttaStepInterpolator prototype; /** Stepsize control exponent. */ private final double exp; /** Safety factor for stepsize control. */ private double safety; /** Minimal reduction factor for stepsize control. */ private double minReduction; /** Maximal growth factor for stepsize control. */ private double maxGrowth; /** Build a Runge-Kutta integrator with the given Butcher array. * @param name name of the method * @param fsal indicate that the method is an <i>fsal</i> * @param c time steps from Butcher array (without the first zero) * @param a internal weights from Butcher array (without the first empty row) * @param b propagation weights for the high order method from Butcher array * @param prototype prototype of the step interpolator to use * @param minStep minimal step (must be positive even for backward * integration), the last step can be smaller than this * @param maxStep maximal step (must be positive even for backward * integration) * @param scalAbsoluteTolerance allowed absolute error * @param scalRelativeTolerance allowed relative error */ protected EmbeddedRungeKuttaIntegrator(final String name, final boolean fsal, final double[] c, final double[][] a, final double[] b, final RungeKuttaStepInterpolator prototype, final double minStep, final double maxStep, final double scalAbsoluteTolerance, final double scalRelativeTolerance) { super(name, minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); this.fsal = fsal; this.c = c; this.a = a; this.b = b; this.prototype = prototype; exp = -1.0 / getOrder(); // set the default values of the algorithm control parameters setSafety(0.9); setMinReduction(0.2); setMaxGrowth(10.0); } /** Build a Runge-Kutta

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> integrator with the given Butcher array. * @param name name of the method * @param fsal indicate that the method is an <i>fsal</i> * @param c time steps from Butcher array (without the first zero) * @param a internal weights from Butcher array (without the first empty row) * @param b propagation weights for the high order method from Butcher array * @param prototype prototype of the step interpolator to use * @param minStep minimal step (must be positive even for backward * integration), the last step can be smaller than this * @param maxStep maximal step (must be positive even for backward * integration) * @param vecAbsoluteTolerance allowed absolute error * @param vecRelativeTolerance allowed relative error */ protected EmbeddedRungeKuttaIntegrator(final String name, final boolean fsal, final double[] c, final double[][] a, final double[] b, final RungeKuttaStepInterpolator prototype, final double minStep, final double maxStep, final double[] vecAbsoluteTolerance, final double[] vecRelativeTolerance) { super(name, minStep, maxStep, vecAbsoluteTolerance, vecRelativeTolerance); this.fsal = fsal; this.c = c; this.a = a; this.b = b; this.prototype = prototype; exp = -1.0 / getOrder(); // set the default values of the algorithm control parameters setSafety(0.9); setMinReduction(0.2); setMaxGrowth(10.0); } /** Get the order of the method. * @return order of the method */ public abstract int getOrder(); /** Get the safety factor for stepsize control. * @return safety factor */ public double getSafety() { return safety; } /** Set the safety factor for stepsize control. * @param safety safety factor */ public void setSafety(final double safety) { this.safety = safety; } /** {@inheritDoc} */ @Override public double integrate(final FirstOrderDifferentialEquations equations, final double t0, final double[] y0, final double t, final double[] y) throws DerivativeException, IntegratorException { sanityChecks(equations, t0, y0, t, y); setEquations(equations); resetEvaluations(); final boolean forward = t > t0; // create some internal working arrays final int stages = c.length + 1; if (y != y0) { System.arraycopy(y0, 0, y, 0, y0.length); } final double[][] yDotK = new double[stages][y0.length]; final double[] yTmp = new double[y0.length]; // set up an interpolator sharing the integrator arrays AbstractStep

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>Interpolator interpolator; if (requiresDenseOutput() || (! eventsHandlersManager.isEmpty())) { final RungeKuttaStepInterpolator rki = (RungeKuttaStepInterpolator) prototype.copy(); rki.reinitialize(this, yTmp, yDotK, forward); interpolator = rki; } else { interpolator = new DummyStepInterpolator(yTmp, forward); } interpolator.storeTime(t0); // set up integration control objects } yTmp[j] = y[j] + stepSize * sum; } computeDerivatives(stepStart + c[k-1] * stepSize, yTmp, yDotK[k]); } // estimate the state at the end of the step for (int j = 0; j < y0.length; ++j) { double sum = b[0] * yDotK[0][j]; for (int l = 1; l < stages; ++l) { sum += b[l] * yDotK[l][j]; } yTmp[j] = y[j] + stepSize * sum; } // estimate the error at the end of the step error = estimateError(yDotK, y, yTmp, stepSize); if (error <= 1.0) { // discrete events handling interpolator.storeTime(stepStart + stepSize); if (manager.evaluateStep(interpolator)) { final double dt = manager.getEventTime() - stepStart; if (Math.abs(dt) <= Math.ulp(stepStart)) { // rejecting the step would lead to a too small next step, we accept it loop = false; } else { // reject the step to match exactly the next switch time hNew = dt; } } else { // accept the step loop = false; } } else { // reject the step and attempt to reduce error by stepsize control final double factor = Math.min(maxGrowth, Math.max(minReduction, safety * Math.pow(error, exp))); hNew = filterStep(stepSize * factor, forward, false); } } // the step has been accepted final double nextStep = stepStart + stepSize; System.arraycopy(yTmp, 0, y, 0, y0.length); manager.stepAccepted(nextStep, y); lastStep = manager.stop(); // provide the step data to the step handler interpolator.storeTime(nextStep); for (StepHandler handler : stepHandlers) { handler.handleStep(interpolator, lastStep); } stepStart = nextStep; if (fsal) { // save the last evaluation for the next step System.arraycopy(yDotK[stages - 1], 0, yDotK[0], 0, y0

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>.length); } if (manager.reset(stepStart, y) && ! lastStep) { // some event handler has triggered changes that // invalidate the derivatives, we need to recompute them computeDerivatives(stepStart, y, yDotK[0]); } if (! lastStep) { // in some rare cases we may get here with stepSize = 0, for example // when an event occurs at integration start, reducing the first step // to zero; we have to reset the step to some safe non zero value stepSize = filterStep(stepSize, forward, true); // stepsize control for next step final double factor = Math.min(maxGrowth, Math.max(minReduction, safety * Math.pow(error, exp))); final double scaledH = stepSize * factor; final double nextT = stepStart + scaledH; final boolean nextIsLast = forward ? (nextT >= t) : (nextT <= t); hNew = filterStep(scaledH, forward, nextIsLast); } } final double stopTime = stepStart; resetInternalState(); return stopTime; } /** Get the minimal reduction factor for stepsize control. * @return minimal reduction factor */ public double getMinReduction() { return minReduction; } /** Set the minimal reduction factor for stepsize control. * @param minReduction minimal reduction factor */ public void setMinReduction(final double minReduction) { this.minReduction = minReduction; } /** Get the maximal growth factor for stepsize control. * @return maximal growth factor */ public double getMaxGrowth() { return maxGrowth; } /** Set the maximal growth factor for stepsize control. * @param maxGrowth maximal growth factor */ public void setMaxGrowth(final double maxGrowth) { this.maxGrowth = maxGrowth; } /** Compute the error ratio. * @param yDotK derivatives computed during the first stages * @param y0 estimate of the step at the start of the step * @param y1 estimate of the step at the end of the step * @param h current step * @return error ratio, greater than 1 if step should be rejected */ protected abstract double estimateError(double[][] yDotK, double[] y0, double[] y1, double h); }

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>Dimension(), matrix.getColumnDimension()); } final int m = matrix.getColumnDimension(); field = matrix.getField(); lu = matrix.getData(); pivot = new int[m]; cachedL = null; cachedU = null; cachedP = null; // Initialize permutation array and parity for (int row = 0; row < m; row++) { pivot[row] = row; } even = true; singular = false; // Loop over columns for (int col = 0; col < m; col++) { T sum = field.getZero(); // upper for (int row = 0; row < col; row++) { final T[] luRow = lu[row]; sum = luRow[col]; for (int i = 0; i < row; i++) { sum = sum.subtract(luRow[i].multiply(lu[i][col])); } luRow[col] = sum; } // lower int nonZero = col; // permutation row for (int row = col; row < m; row++) { final T[] luRow = lu[row]; sum = luRow[col]; for (int i = 0; i < col; i++) { sum = sum.subtract(luRow[i].multiply(lu[i][col])); } luRow[col] = sum; if (lu[nonZero][col].equals(field.getZero())) { // try to select a better permutation choice ++nonZero; } } // Singularity check if (nonZero >= m) { singular = true; return; } // Pivot if necessary if (nonZero != col) { T tmp = field.getZero(); for (int i = 0; i < m; i++) { tmp = lu[nonZero][i]; lu[nonZero][i] = lu[col][i]; lu[col][i] = tmp; } int temp = pivot[nonZero]; pivot[nonZero] = pivot[col]; pivot[col] = temp; even = !even; } // Divide the lower elements by the "winning" diagonal elt. final T luDiag = lu[col][col]; for (int row = col + 1; row < m; row++) { final T[] luRow = lu[row]; luRow[col] = luRow[col].divide(luDiag); } } } /** {@inheritDoc} */ public FieldMatrix<T> getL() { if ((cachedL == null) && !singular) { final int m = pivot.length; cachedL = new Array2DRowFieldMatrix<T>(field, m, m); for (int i = 0; i < m; ++i) { final T[] luI = lu[

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>i]; for (int j = 0; j < i; ++j) { cachedL.setEntry(i, j, luI[j]); } cachedL.setEntry(i, i, field.getOne()); } } return cachedL; } /** {@inheritDoc} */ public FieldMatrix<T> getU() { if ((cachedU == null) && !singular) { final int m = pivot.length; cachedU = new Array2DRowFieldMatrix<T>(field, m, m); for (int i = 0; i < m; ++i) { final T[] luI = lu[i]; for (int j = i; j < m; ++j) { cachedU.setEntry(i, j, luI[j]); } } } return cachedU; } /** {@inheritDoc} */ public FieldMatrix<T> getP() { if ((cachedP == null) && !singular) { final int m = pivot.length; cachedP = new Array2DRowFieldMatrix<T>(field, m, m); for (int i = 0; i < m; ++i) { cachedP.setEntry(i, pivot[i], field.getOne()); } } return cachedP; } /** {@inheritDoc} */ public int[] getPivot() { return pivot.clone(); } /** {@inheritDoc} */ public T getDeterminant() { if (singular) { return field.getZero(); } else { final int m = pivot.length; T determinant = even ? field.getOne() : field.getZero().subtract(field.getOne()); for (int i = 0; i < m; i++) { determinant = determinant.multiply(lu[i][i]); } return determinant; } } /** {@inheritDoc} */ public FieldDecompositionSolver<T> getSolver() { return new Solver<T>(field, lu, pivot, singular); } /** Specialized solver. */ private static class Solver<T extends FieldElement<T>> implements FieldDecompositionSolver<T> { /** Serializable version identifier. */ private static final long serialVersionUID = -6353105415121373022L; /** Field to which the elements belong. */ private final Field<T> field; /** Entries of LU decomposition. */ private final T lu[][]; /** Pivot permutation associated with LU decomposition. */ private final int[] pivot; /** Singularity indicator. */ private final boolean singular; /** * Build a solver from decomposed matrix. * @param field field to which the matrix elements belong * @param lu entries of LU decomposition * @param pivot pivot permutation associated with LU decomposition * @param singular singularity indicator */ private Solver(final

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> Field<T> field, final T[][] lu, final int[] pivot, final boolean singular) { this.field = field; this.lu = lu; this.pivot = pivot; this.singular = singular; } /** {@inheritDoc} */ public boolean isNonSingular() { return !singular; } /** {@inheritDoc} */ public T[] solve(T[] b) throws IllegalArgumentException, InvalidMatrixException { final int m = pivot.length; if (b.length != m) { throw MathRuntimeException.createIllegalArgumentException( "vector length mismatch: got {0} but expected {1}", b.length, m); } if (singular) { throw new SingularMatrixException(); } @SuppressWarnings("unchecked") // field is of type T final T[] bp = (T[]) Array.newInstance(field.getZero().getClass(), m); // Apply permutations to b for (int row = 0; row < m; row++) { bp[row] = b[pivot[row]]; } // Solve LY = b for (int col = 0; col < m; col++) { final T bpCol = bp[col]; for (int i = col + 1; i < m; i++) { bp[i] = bp[i].subtract(bpCol.multiply(lu[i][col])); } } // Solve UX = Y for (int col = m - 1; col >= 0; col--) { bp[col] = bp[col].divide(lu[col][col]); final T bpCol = bp[col]; for (int i = 0; i < col; i++) { bp[i] = bp[i].subtract(bpCol.multiply(lu[i][col])); } } return bp; } /** {@inheritDoc} */ public FieldVector<T> solve(FieldVector<T> b) throws IllegalArgumentException, InvalidMatrixException { try { return solve((ArrayFieldVector<T>) b); } catch (ClassCastException cce) { final int m = pivot.length; if (b.getDimension() != m) { throw MathRuntimeException.createIllegalArgumentException( "vector length mismatch: got {0} but expected {1}", b.getDimension(), m); } if (singular) { throw new SingularMatrixException(); } @SuppressWarnings("unchecked") // field is of type T final T[] bp = (T[]) Array.newInstance(field.getZero().getClass(), m); // Apply permutations to b for (int row = 0; row < m; row++) { bp[row] = b.getEntry(pivot[row]); } // Solve LY = b for (int col = 0; col < m; col++) { final T bpCol = bp[col]; for

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> (int i = col + 1; i < m; i++) { bp[i] = bp[i].subtract(bpCol.multiply(lu[i][col])); } } // Solve UX = Y for (int col = m - 1; col >= 0; col--) { bp[col] = bp[col].divide(lu[col][col]); final T bpCol = bp[col]; for (int i = 0; i < col; i++) { bp[i] = bp[i].subtract(bpCol.multiply(lu[i][col])); } } return new ArrayFieldVector<T>(bp, false); } } /** Solve the linear equation A &times; X = B. * <p>The A matrix is implicit here. It is </p> * @param b right-hand side of the equation A &times; X = B * @return a vector X such that A &times; X = B * @exception IllegalArgumentException if matrices dimensions don't match * @exception InvalidMatrixException if decomposed matrix is singular */ public ArrayFieldVector<T> solve(ArrayFieldVector<T> b) throws IllegalArgumentException, InvalidMatrixException { return new ArrayFieldVector<T>(solve(b.getDataRef()), false); } /** {@inheritDoc} */ public FieldMatrix<T> solve(FieldMatrix<T> b) throws IllegalArgumentException, InvalidMatrixException { final int m = pivot.length; if (b.getRowDimension() != m) { throw MathRuntimeException.createIllegalArgumentException( "dimensions mismatch: got {0}x{1} but expected {2}x{3}", b.getRowDimension(), b.getColumnDimension(), m, "n"); } if (singular) { throw new SingularMatrixException(); } final int nColB = b.getColumnDimension(); // Apply permutations to b @SuppressWarnings("unchecked") // field is of type T final T[][] bp = (T[][]) Array.newInstance(field.getZero().getClass(), new int[] { m, nColB }); for (int row = 0; row < m; row++) { final T[] bpRow = bp[row]; final int pRow = pivot[row]; for (int col = 0; col < nColB; col++) { bpRow[col] = b.getEntry(pRow, col); } } // Solve LY = b for (int col = 0; col < m; col++) { final T[] bpCol = bp[col]; for (int i = col + 1; i < m; i++) { final T[] bpI = bp[i]; final T luICol = lu[i][col]; for (int j = 0; j < nColB; j++) { bpI[j] = bpI[j].

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>subtract(bpCol[j].multiply(luICol)); } } } // Solve UX = Y for (int col = m - 1; col >= 0; col--) { final T[] bpCol = bp[col]; final T luDiag = lu[col][col]; for (int j = 0; j < nColB; j++) { bpCol[j] = bpCol[j].divide(luDiag); } for (int i = 0; i < col; i++) { final T[] bpI = bp[i]; final T luICol = lu[i][col]; for (int j = 0; j < nColB; j++) { bpI[j] = bpI[j].subtract(bpCol[j].multiply(luICol)); } } } return new Array2DRowFieldMatrix<T>(bp, false); } /** {@inheritDoc} */ public FieldMatrix<T> getInverse() throws InvalidMatrixException { final int m = pivot.length; final T one = field.getOne(); FieldMatrix<T> identity = new Array2DRowFieldMatrix<T>(field, m, m); for (int i = 0; i < m; ++i) { identity.setEntry(i, i, one); } return solve(identity); } } }

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> = getField().getZero(); for (int i = 0; i < nSum; i++) { sum = sum.add(dataRow[i].multiply(m.data[i][col])); } outDataRow[col] = sum; } } return new Array2DRowFieldMatrix<T>(outData, false); } /** {@inheritDoc} */ @Override public T[][] getData() { return copyOut(); } /** * Returns a reference to the underlying data array. * <p> * Does <strong>not</strong> make a fresh copy of the underlying data.</p> * * @return 2-dimensional array of entries */ public T[][] getDataRef() { return data; } /** {@inheritDoc} */ @Override public void setSubMatrix(final T[][] subMatrix, final int row, final int column) throws MatrixIndexException { if (data == null) { if (row > 0) { throw MathRuntimeException.createIllegalStateException( "first {0} rows are not initialized yet", row); } if (column > 0) { throw MathRuntimeException.createIllegalStateException( "first {0} columns are not initialized yet", column); } final int nRows = subMatrix.length; if (nRows == 0) { throw MathRuntimeException.createIllegalArgumentException( AT_LEAST_ONE_ROW_MESSAGE); } final int nCols = subMatrix[0].length; if (nCols == 0) { throw MathRuntimeException.createIllegalArgumentException( AT_LEAST_ONE_COLUMN_MESSAGE); } data = buildArray(getField(), subMatrix.length, nCols); for (int i = 0; i < data.length; ++i) { if (subMatrix[i].length != nCols) { throw MathRuntimeException.createIllegalArgumentException( DIFFERENT_ROWS_LENGTHS_MESSAGE, nCols, subMatrix[i].length); } System.arraycopy(subMatrix[i], 0, data[i + row], column, nCols); } } else { super.setSubMatrix(subMatrix, row, column); } } /** {@inheritDoc} */ @Override public T getEntry(final int row, final int column) throws MatrixIndexException { try { return data[row][column]; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( NO_ENTRY_MESSAGE, row, column, getRowDimension(), getColumnDimension()); } } /** {@inheritDoc} */ @Override public void setEntry(final int row, final int column, final T value) throws MatrixIndexException { try { data[row][column] = value; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( NO_ENTRY_MESSAGE, row, column, getRowDimension

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>(), getColumnDimension()); } } /** {@inheritDoc} */ @Override public void addToEntry(final int row, final int column, final T increment) throws MatrixIndexException { try { data[row][column] = data[row][column].add(increment); } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( NO_ENTRY_MESSAGE, row, column, getRowDimension(), getColumnDimension()); } } /** {@inheritDoc} */ @Override public void multiplyEntry(final int row, final int column, final T factor) throws MatrixIndexException { try { data[row][column] = data[row][column].multiply(factor); } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( NO_ENTRY_MESSAGE, row, column, getRowDimension(), getColumnDimension()); } } /** {@inheritDoc} */ @Override public int getRowDimension() { return (data == null) ? 0 : data.length; } /** {@inheritDoc} */ @Override public int getColumnDimension() { return ((data == null) || (data[0] == null)) ? 0 : data[0].length; } /** {@inheritDoc} */ @Override public T[] operate(final T[] v) throws IllegalArgumentException { final int nRows = this.getRowDimension(); final int nCols = this.getColumnDimension(); if (v.length != nCols) { throw MathRuntimeException.createIllegalArgumentException( VECTOR_LENGTHS_MISMATCH, v.length, nCols); } final T[] out = buildArray(getField(), nRows); for (int row = 0; row < nRows; row++) { final T[] dataRow = data[row]; T sum = getField().getZero(); for (int i = 0; i < nCols; i++) { sum = sum.add(dataRow[i].multiply(v[i])); } out[row] = sum; } return out; } /** {@inheritDoc} */ @Override public T[] preMultiply(final T[] v) throws IllegalArgumentException { final int nRows = getRowDimension(); final int nCols = getColumnDimension(); if (v.length != nRows) { throw MathRuntimeException.createIllegalArgumentException( VECTOR_LENGTHS_MISMATCH, v.length, nRows); } final T[] out = buildArray(getField(), nCols); for (int col = 0; col < nCols; ++col) { T sum = getField().getZero(); for (int i = 0; i < nRows; ++i) { sum = sum.add(data[i][col].multiply(v[i])); } out[col] = sum; } return out; } /** {@inheritDoc} */ @

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>Override public T walkInRowOrder(final FieldMatrixChangingVisitor<T> visitor) throws MatrixVisitorException { final int rows = getRowDimension(); final int columns = getColumnDimension(); visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int i = 0; i < rows; ++i) { final T[] rowI = data[i]; for (int j = 0; j < columns; ++j) { rowI[j] = visitor.visit(i, j, rowI[j]); } } return visitor.end(); } /** {@inheritDoc} */ @Override public T walkInRowOrder(final FieldMatrixPreservingVisitor<T> visitor) throws MatrixVisitorException { final int rows = getRowDimension(); final int columns = getColumnDimension(); visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int i = 0; i < rows; ++i) { final T[] rowI = data[i]; for (int j = 0; j < columns; ++j) { visitor.visit(i, j, rowI[j]); } } return visitor.end(); } /** {@inheritDoc} */ @Override public T walkInRowOrder(final FieldMatrixChangingVisitor<T> visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException, MatrixVisitorException { checkSubMatrixIndex(startRow, endRow, startColumn, endColumn); visitor.start(getRowDimension(), getColumnDimension(), startRow, endRow, startColumn, endColumn); for (int i = startRow; i <= endRow; ++i) { final T[] rowI = data[i]; for (int j = startColumn; j <= endColumn; ++j) { rowI[j] = visitor.visit(i, j, rowI[j]); } } return visitor.end(); } /** {@inheritDoc} */ @Override public T walkInRowOrder(final FieldMatrixPreservingVisitor<T> visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException, MatrixVisitorException { checkSubMatrixIndex(startRow, endRow, startColumn, endColumn); visitor.start(getRowDimension(), getColumnDimension(), startRow, endRow, startColumn, endColumn); for (int i = startRow; i <= endRow; ++i) { final T[] rowI = data[i]; for (int j = startColumn; j <= endColumn; ++j) { visitor.visit(i, j, rowI[j]); } } return visitor.end(); }

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> /** {@inheritDoc} */ @Override public T walkInColumnOrder(final FieldMatrixChangingVisitor<T> visitor) throws MatrixVisitorException { final int rows = getRowDimension(); final int columns = getColumnDimension(); visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int j = 0; j < columns; ++j) { for (int i = 0; i < rows; ++i) { final T[] rowI = data[i]; rowI[j] = visitor.visit(i, j, rowI[j]); } } return visitor.end(); } /** {@inheritDoc} */ @Override public T walkInColumnOrder(final FieldMatrixPreservingVisitor<T> visitor) throws MatrixVisitorException { final int rows = getRowDimension(); final int columns = getColumnDimension(); visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int j = 0; j < columns; ++j) { for (int i = 0; i < rows; ++i) { visitor.visit(i, j, data[i][j]); } } return visitor.end(); } /** {@inheritDoc} */ @Override public T walkInColumnOrder(final FieldMatrixChangingVisitor<T> visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException, MatrixVisitorException { checkSubMatrixIndex(startRow, endRow, startColumn, endColumn); visitor.start(getRowDimension(), getColumnDimension(), startRow, endRow, startColumn, endColumn); for (int j = startColumn; j <= endColumn; ++j) { for (int i = startRow; i <= endRow; ++i) { final T[] rowI = data[i]; rowI[j] = visitor.visit(i, j, rowI[j]); } } return visitor.end(); } /** {@inheritDoc} */ @Override public T walkInColumnOrder(final FieldMatrixPreservingVisitor<T> visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException, MatrixVisitorException { checkSubMatrixIndex(startRow, endRow, startColumn, endColumn); visitor.start(getRowDimension(), getColumnDimension(), startRow, endRow, startColumn, endColumn); for (int j = startColumn; j <= endColumn; ++j) { for (int i = startRow; i <= endRow; ++i) { visitor.visit(i, j, data[i][j]); } } return visitor.end(); } /** * Returns a fresh copy of the underlying data

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> array. * * @return a copy of the underlying data array. */ private T[][] copyOut() { final int nRows = this.getRowDimension(); final T[][] out = buildArray(getField(), nRows, getColumnDimension()); // can't copy 2-d array in one shot, otherwise get row references for (int i = 0; i < nRows; i++) { System.arraycopy(data[i], 0, out[i], 0, data[i].length); } return out; } /** * Replaces data with a fresh copy of the input array. * <p> * Verifies that the input array is rectangular and non-empty.</p> * * @param in data to copy in * @throws IllegalArgumentException if input array is empty or not * rectangular * @throws NullPointerException if input array is null */ private void copyIn(final T[][] in) { setSubMatrix(in, 0, 0); } }

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.math.ode.nonstiff; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import org.apache.commons.math.ode.DerivativeException; import org.apache.commons.math.ode.FirstOrderIntegrator; import org.apache.commons.math.ode.IntegratorException; import org.apache.commons.math.ode.TestProblem1; import org.apache.commons.math.ode.TestProblem5; import org.apache.commons.math.ode.TestProblem6; import org.apache.commons.math.ode.TestProblemHandler; import org.junit.Test; public class AdamsMoultonIntegratorTest { @Test(expected=IntegratorException.class) public void dimensionCheck() throws DerivativeException, IntegratorException { TestProblem1 pb = new TestProblem1(); FirstOrderIntegrator integ = new AdamsMoultonIntegrator(2, 0.0, 1.0, 1.0e-10, 1.0e-10); integ.integrate(pb, 0.0, new double[pb.getDimension()+10], 1.0, new double[pb.getDimension()+10]); } @Test(expected=IntegratorException.class) public void testMinStep() throws DerivativeException, IntegratorException { TestProblem1 pb = new TestProblem1(); double minStep = 0.1 * (pb.getFinalTime() - pb.getInitialTime()); double maxStep = pb.getFinalTime() - pb.getInitialTime(); double[] vecAbsoluteTolerance = { 1.0e-15, 1.0e-16 }; double[] vecRelativeTolerance = { 1.0e-15, 1.0e-16 }; FirstOrderIntegrator integ = new AdamsMoultonIntegrator(4, minStep, maxStep, vecAbsoluteTolerance, vecRelativeTolerance); TestProblemHandler

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> handler = new TestProblemHandler(pb, integ); integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); } @Test public void testIncreasingTolerance() throws DerivativeException, IntegratorException { int previousCalls = Integer.MAX_VALUE; for (int i = -12; i < -2; ++i) { TestProblem1 pb = new TestProblem1(); double minStep = 0; double maxStep = pb.getFinalTime() - pb.getInitialTime(); double scalAbsoluteTolerance = Math.pow(10.0, i); double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance; FirstOrderIntegrator integ = new AdamsMoultonIntegrator(4, minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); TestProblemHandler handler = new TestProblemHandler(pb, integ); integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); // the 0.15 and 3.0 factors are only valid for this test // and has been obtained from trial and error // there is no general relation between local and global errors assertTrue(handler.getMaximalValueError() > (0.15 * scalAbsoluteTolerance)); assertTrue(handler.getMaximalValueError() < (3.0 * scalAbsoluteTolerance)); assertEquals(0, handler.getMaximalTimeError(), 1.0e-16); int calls = pb.getCalls(); assertEquals(integ.getEvaluations(), calls); assertTrue(calls <= previousCalls); previousCalls = calls; } } @Test(expected = DerivativeException.class) public void exceedMaxEvaluations() throws DerivativeException, IntegratorException { TestProblem1 pb = new TestProblem1(); double range = pb.getFinalTime() - pb.getInitialTime(); AdamsMoultonIntegrator integ = new AdamsMoultonIntegrator(2, 0, range, 1.0e-12, 1.0e-12); TestProblemHandler handler = new TestProblemHandler(pb, integ); integ.addStepHandler(handler); integ.setMaxEvaluations(650); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); } @Test public void backward() throws DerivativeException, IntegratorException { TestProblem5 pb = new TestProblem5(); double range = Math.abs(pb.getFinalTime() - pb.getInitialTime()); FirstOrderIntegr

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>ator integ = new AdamsMoultonIntegrator(4, 0, range, 1.0e-12, 1.0e-12); TestProblemHandler handler = new TestProblemHandler(pb, integ); integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); assertTrue(handler.getLastError() < 1.0e-9); assertTrue(handler.getMaximalValueError() < 1.0e-9); assertEquals(0, handler.getMaximalTimeError(), 1.0e-16); assertEquals("Adams-Moulton", integ.getName()); } @Test public void polynomial() throws DerivativeException, IntegratorException { TestProblem6 pb = new TestProblem6(); double range = Math.abs(pb.getFinalTime() - pb.getInitialTime()); for (int nSteps = 1; nSteps < 7; ++nSteps) { AdamsMoultonIntegrator integ = new AdamsMoultonIntegrator(nSteps, 1.0e-6 * range, 0.1 * range, 1.0e-9, 1.0e-9); TestProblemHandler handler = new TestProblemHandler(pb, integ); integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); if (nSteps < 4) { assertTrue(integ.getEvaluations() > 140); } else { assertTrue(integ.getEvaluations() < 90); } } } }

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.math.ode; import org.apache.commons.math.ode.DerivativeException; import org.apache.commons.math.ode.ODEIntegrator; import org.apache.commons.math.ode.sampling.StepHandler; import org.apache.commons.math.ode.sampling.StepInterpolator; /** * This class is used to handle steps for the test problems * integrated during the junit tests for the ODE integrators. */ public class TestProblemHandler implements StepHandler { /** Associated problem. */ private TestProblemAbstract problem; /** Maximal errors encountered during the integration. */ private double maxValueError; private double maxTimeError; /** Error at the end of the integration. */ private double lastError; /** Time at the end of integration. */ private double lastTime; /** ODE solver used. */ private ODEIntegrator integrator; /** Expected start for step. */ private double expectedStepStart; /** * Simple constructor. * @param problem problem for which steps should be handled * @param integrator ODE solver used */ public TestProblemHandler(TestProblemAbstract problem, ODEIntegrator integrator) { this.problem = problem; this.integrator = integrator; reset(); } public boolean requiresDenseOutput() { return true; } public void reset() { maxValueError = 0; maxTimeError = 0; lastError = 0; expectedStepStart = Double.NaN; } public void handleStep(StepInterpolator interpolator, boolean isLast) throws DerivativeException { double start = integrator.getCurrentStepStart(); if (Math.abs((start - problem.getInitialTime()) / integrator.getCurrentSignedStepsize()) > 0.001) { // multistep integrators do not handle the first steps themselves // so we have to make sure the integrator we look at has really started its work if (!Double.isNaN(expectedStepStart)) { maxTimeError = Math.max(maxTimeError

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>, Math.abs(start - expectedStepStart)); } expectedStepStart = start + integrator.getCurrentSignedStepsize(); } double pT = interpolator.getPreviousTime(); double cT = interpolator.getCurrentTime(); double[] errorScale = problem.getErrorScale(); // store the error at the last step if (isLast) { double[] interpolatedY = interpolator.getInterpolatedState(); double[] theoreticalY = problem.computeTheoreticalState(cT); for (int i = 0; i < interpolatedY.length; ++i) { double error = Math.abs(interpolatedY[i] - theoreticalY[i]); lastError = Math.max(error, lastError); } lastTime = cT; } // walk through the step for (int k = 0; k <= 20; ++k) { double time = pT + (k * (cT - pT)) / 20; interpolator.setInterpolatedTime(time); double[] interpolatedY = interpolator.getInterpolatedState(); double[] theoreticalY = problem.computeTheoreticalState(interpolator.getInterpolatedTime()); // update the errors for (int i = 0; i < interpolatedY.length; ++i) { double error = errorScale[i] * Math.abs(interpolatedY[i] - theoreticalY[i]); maxValueError = Math.max(error, maxValueError); } } } /** * Get the maximal value error encountered during integration. * @return maximal value error */ public double getMaximalValueError() { return maxValueError; } /** * Get the maximal time error encountered during integration. * @return maximal time error */ public double getMaximalTimeError() { return maxTimeError; } /** * Get the error at the end of the integration. * @return error at the end of the integration */ public double getLastError() { return lastError; } /** * Get the time at the end of the integration. * @return time at the end of the integration. */ public double getLastTime() { return lastTime; } }

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> predicted vector, the corrected vector is computed as follows: * <ul> * <li>y<sub>n+1</sub> = y<sub>n</sub> + S<sub>1</sub>(n+1) + [ -1 +1 -1 +1 ... &plusmn;1 ] r<sub>n+1</sub></li> * <li>s<sub>1</sub>(n+1) = h f(t<sub>n+1</sub>, y<sub>n+1</sub>)</li> * <li>r<sub>n+1</sub> = R<sub>n+1</sub> + (s<sub>1</sub>(n+1) - S<sub>1</sub>(n+1)) P<sup>-1</sup> u</li> * </ul> * where the upper case Y<sub>n+1</sub>, S<sub>1</sub>(n+1) and R<sub>n+1</sub> represent the * predicted states whereas the lower case y<sub>n+1</sub>, s<sub>n+1</sub> and r<sub>n+1</sub> * represent the corrected states.</p> * * <p>The P<sup>-1</sup>u vector and the P<sup>-1</sup> A P matrix do not depend on the state, * they only depend on k and therefore are precomputed once for all.</p> * * @version $Revision$ $Date$ * @since 2.0 */ public class AdamsMoultonIntegrator extends AdamsIntegrator { /** * Build an Adams-Moulton integrator with the given order and error control parameters. * @param nSteps number of steps of the method excluding the one being computed * @param minStep minimal step (must be positive even for backward * integration), the last step can be smaller than this * @param maxStep maximal step (must be positive even for backward * integration) * @param scalAbsoluteTolerance allowed absolute error * @param scalRelativeTolerance allowed relative error * @exception IllegalArgumentException if order is 1 or less */ public AdamsMoultonIntegrator(final int nSteps, final double minStep, final double maxStep, final double scalAbsoluteTolerance, final double scalRelativeTolerance) throws IllegalArgumentException { super("Adams-Moulton", nSteps, nSteps + 1, minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); } /** * Build an Adams-Moulton integrator with the given order and error control parameters. * @param nSteps number of steps of the method excluding the one being computed * @param minStep minimal step (must be positive even for backward * integration), the last step can be smaller than this * @

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>param maxStep maximal step (must be positive even for backward * integration) * @param vecAbsoluteTolerance allowed absolute error * @param vecRelativeTolerance allowed relative error * @exception IllegalArgumentException if order is 1 or less */ public AdamsMoultonIntegrator(final int nSteps, final double minStep, final double maxStep, final double[] vecAbsoluteTolerance, final double[] vecRelativeTolerance) throws IllegalArgumentException { super("Adams-Moulton", nSteps, nSteps + 1, minStep, maxStep, vecAbsoluteTolerance, vecRelativeTolerance); } /** {@inheritDoc} */ @Override public double integrate(final FirstOrderDifferentialEquations equations, final double t0, final double[] y0, final double t, final double[] y) throws DerivativeException, IntegratorException { final int n = y0.length; sanityChecks(equations, t0, y0, t, y); setEquations(equations); resetEvaluations(); final boolean forward = t > t0; // initialize working arrays if (y != y0) { System.arraycopy(y0, 0, y, 0, n); } final double[] yDot = new double[y0.length]; final double[] yTmp = new double[y0.length]; // set up two interpolators sharing the integrator arrays final NordsieckStepInterpolator interpolator = new NordsieckStepInterpolator(); interpolator.reinitialize(y, forward); final NordsieckStepInterpolator interpolatorTmp = new NordsieckStepInterpolator(); interpolatorTmp.reinitialize(yTmp, forward); // set up integration control objects for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); // compute the initial Nordsieck vector using the configured starter integrator start(t0, y, t); interpolator.reinitialize(stepStart, stepSize, scaled, nordsieck); interpolator.storeTime(stepStart); double hNew = stepSize; interpolator.rescale(hNew); boolean lastStep = false; while (!lastStep) { // shift all data interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { stepSize = hNew; // predict a first estimate of the state at step end (P in the PECE sequence) final double stepEnd = stepStart + stepSize; interpolator.setInterpolatedTime(stepEnd); System.arraycopy(interpolator.getInterpolatedState(), 0, yTmp, 0, y0.length); // evaluate a first estimate of the derivative (first E in the PECE sequence) computeDerivatives(stepEnd, yTmp, yDot); //

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> update Nordsieck vector final double[] predictedScaled = new double[y0.length]; for (int j = 0; j < y0.length; ++j) { predictedScaled[j] = stepSize * yDot[j]; } final Array2DRowRealMatrix nordsieckTmp = updateHighOrderDerivativesPhase1(nordsieck); updateHighOrderDerivativesPhase2(scaled, predictedScaled, nordsieckTmp); // apply correction (C in the PECE sequence) error = nordsieckTmp.walkInOptimizedOrder(new Corrector(y, predictedScaled, yTmp)); if (error <= 1.0) { // evaluate a final estimate of the derivative (second E in the PECE sequence) computeDerivatives(stepEnd, yTmp, yDot); // update Nordsieck vector final double[] correctedScaled = new double[y0.length]; for (int j = 0; j < y0.length; ++j) { correctedScaled[j] = stepSize * yDot[j]; } updateHighOrderDerivativesPhase2(predictedScaled, correctedScaled, nordsieckTmp); // discrete events handling interpolatorTmp.reinitialize(stepEnd, stepSize, correctedScaled, nordsieckTmp); interpolatorTmp.storeTime(stepStart); interpolatorTmp.shift(); interpolatorTmp.storeTime(stepEnd); if (manager.evaluateStep(interpolatorTmp)) { final double dt = manager.getEventTime() - stepStart; if (Math.abs(dt) <= Math.ulp(stepStart)) { // rejecting the step would lead to a too small next step, we accept it loop = false; } else { // reject the step to match exactly the next switch time hNew = dt; interpolator.rescale(hNew); } } else { // accept the step scaled = correctedScaled; nordsieck = nordsieckTmp; interpolator.reinitialize(stepEnd, stepSize, scaled, nordsieck); loop = false; } } else { // reject the step and attempt to reduce error by stepsize control final double factor = computeStepGrowShrinkFactor(error); hNew = filterStep(stepSize * factor, forward, false); interpolator.rescale(hNew); } } // the step has been accepted (may have been truncated) final double nextStep = stepStart + stepSize; System.arraycopy(yTmp, 0, y, 0, n); interpolator.storeTime(nextStep); manager.stepAccepted(nextStep, y); lastStep = manager.stop(); // provide the step data to the step handler for (StepHandler handler : stepHandlers) { interpolator.setInterpolatedTime(nextStep); handler.handle

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> == 0) { after[column] -= value; } else { after[column] += value; } } /** * End visiting te Nordsieck vector. * <p>The correction is used to control stepsize. So its amplitude is * considered to be an error, which must be normalized according to * error control settings. If the normalized value is greater than 1, * the correction was too large and the step must be rejected.</p> * @return the normalized correction, if greater than 1, the step * must be rejected */ public double end() { double error = 0; for (int i = 0; i < after.length; ++i) { after[i] += previous[i] + scaled[i]; final double yScale = Math.max(Math.abs(previous[i]), Math.abs(after[i])); final double tol = (vecAbsoluteTolerance == null) ? (scalAbsoluteTolerance + scalRelativeTolerance * yScale) : (vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * yScale); final double ratio = (after[i] - before[i]) / tol; error += ratio * ratio; } return Math.sqrt(error / after.length); } } }

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>ExceededException, FunctionEvaluationException { return solve(f, min, max, initial); } /** * Find a zero in the given interval with an initial guess. * <p>Throws <code>IllegalArgumentException</code> if the values of the * function at the three points have the same sign (note that it is * allowed to have endpoints with the same sign if the initial point has * opposite sign function-wise).</p> * * @param f function to solve. * @param min the lower bound for the interval. * @param max the upper bound for the interval. * @param initial the start value to use (must be set to min if no * initial point is known). * @return the value where the function is zero * @throws MaxIterationsExceededException the maximum iteration count * is exceeded * @throws FunctionEvaluationException if an error occurs evaluating * the function * @throws IllegalArgumentException if initial is not between min and max * (even if it <em>is</em> a root) */ public double solve(final UnivariateRealFunction f, final double min, final double max, final double initial) throws MaxIterationsExceededException, FunctionEvaluationException { clearResult(); verifySequence(min, initial, max); // return the initial guess if it is good enough double yInitial = f.value(initial); if (Math.abs(yInitial) <= functionValueAccuracy) { setResult(initial, 0); return result; } // return the first endpoint if it is good enough double yMin = f.value(min); if (Math.abs(yMin) <= functionValueAccuracy) { setResult(yMin, 0); return result; } // reduce interval if min and initial bracket the root if (yInitial * yMin < 0) { return solve(f, min, yMin, initial, yInitial, min, yMin); } // return the second endpoint if it is good enough double yMax = f.value(max); if (Math.abs(yMax) <= functionValueAccuracy) { setResult(yMax, 0); return result; } // reduce interval if initial and max bracket the root if (yInitial * yMax < 0) { return solve(f, initial, yInitial, max, yMax, initial, yInitial); } // full Brent algorithm starting with provided initial guess return solve(f, min, yMin, max, yMax, initial, yInitial); } /** * Find a zero in the given interval. * <p> * Requires that the values of the function at the endpoints have opposite * signs. An <code>IllegalArgumentException</code> is thrown if this is not * the case.</p> * * @param f the function to solve * @param min the lower bound for the interval. * @

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>param max the upper bound for the interval. * @return the value where the function is zero * @throws MaxIterationsExceededException if the maximum iteration count is exceeded * @throws FunctionEvaluationException if an error occurs evaluating the * function * @throws IllegalArgumentException if min is not less than max or the * signs of the values of the function at the endpoints are not opposites */ public double solve(final UnivariateRealFunction f, final double min, final double max) throws MaxIterationsExceededException, FunctionEvaluationException { clearResult(); verifyInterval(min, max); double ret = Double.NaN; double yMin = f.value(min); double yMax = f.value(max); // Verify bracketing double sign = yMin * yMax; if (sign > 0) { // check if either value is close to a zero if (Math.abs(yMin) <= functionValueAccuracy) { setResult(min, 0); ret = min; } else if (Math.abs(yMax) <= functionValueAccuracy) { setResult(max, 0); ret = max; } else { // neither value is close to zero and min and max do not bracket root. throw MathRuntimeException.createIllegalArgumentException( "function values at endpoints do not have different signs. " + "Endpoints: [{0}, {1}], Values: [{2}, {3}]", min, max, yMin, yMax); } } else if (sign < 0){ // solve using only the first endpoint as initial guess ret = solve(f, min, yMin, max, yMax, min, yMin); } else { // either min or max is a root if (yMin == 0.0) { ret = min; } else { ret = max; } } return ret; } /** * Find a zero starting search according to the three provided points. * @param f the function to solve * @param x0 old approximation for the root * @param y0 function value at the approximation for the root * @param x1 last calculated approximation for the root * @param y1 function value at the last calculated approximation * for the root * @param x2 bracket point (must be set to x0 if no bracket point is * known, this will force starting with linear interpolation) * @param y2 function value at the bracket point. * @return the value where the function is zero * @throws MaxIterationsExceededException if the maximum iteration count * is exceeded * @throws FunctionEvaluationException if an error occurs evaluating * the function */ private double solve(final UnivariateRealFunction f, double x0, double y0, double x1, double y1, double x2, double y2) throws MaxIterationsExceededException, FunctionEvaluationException { double delta = x1 -

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> x0; double oldDelta = delta; int i = 0; while (i < maximalIterationCount) { if (Math.abs(y2) < Math.abs(y1)) { // use the bracket point if is better than last approximation x0 = x1; x1 = x2; x2 = x0; y0 = y1; y1 = y2; y2 = y0; } if (Math.abs(y1) <= functionValueAccuracy) { // Avoid division by very small values. Assume // the iteration has converged (the problem may // still be ill conditioned) setResult(x1, i); return result; } double dx = x2 - x1; double tolerance = Math.max(relativeAccuracy * Math.abs(x1), absoluteAccuracy); if (Math.abs(dx) <= tolerance) { setResult(x1, i); return result; } if ((Math.abs(oldDelta) < tolerance) || (Math.abs(y0) <= Math.abs(y1))) { // Force bisection. delta = 0.5 * dx; oldDelta = delta; } else { double r3 = y1 / y0; double p; double p1; // the equality test (x0 == x2) is intentional, // it is part of the original Brent's method, // it should NOT be replaced by proximity test if (x0 == x2) { // Linear interpolation. p = dx * r3; p1 = 1.0 - r3; } else { // Inverse quadratic interpolation. double r1 = y0 / y2; double r2 = y1 / y2; p = r3 * (dx * r1 * (r1 - r2) - (x1 - x0) * (r2 - 1.0)); p1 = (r1 - 1.0) * (r2 - 1.0) * (r3 - 1.0); } if (p > 0.0) { p1 = -p1; } else { p = -p; } if (2.0 * p >= 1.5 * dx * p1 - Math.abs(tolerance * p1) || p >= Math.abs(0.5 * oldDelta * p1)) { // Inverse quadratic interpolation gives a value // in the wrong direction, or progress is slow. // Fall back to bisection. delta = 0.5 * dx; oldDelta = delta; } else { oldDelta = delta; delta = p / p1; } } // Save old X1, Y1 x0 = x1; y0 = y1

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>; // Compute new X1, Y1 if (Math.abs(delta) > tolerance) { x1 = x1 + delta; } else if (dx > 0.0) { x1 = x1 + 0.5 * tolerance; } else if (dx <= 0.0) { x1 = x1 - 0.5 * tolerance; } y1 = f.value(x1); if ((y1 > 0) == (y2 > 0)) { x2 = x0; y2 = y0; delta = x1 - x0; oldDelta = delta; } i++; } throw new MaxIterationsExceededException(maximalIterationCount); } }

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>KLast[k], 0, yDotKLast[k], 0, dimension); } v = new double[7][]; for (int k = 0; k < v.length; ++k) { v[k] = new double[dimension]; System.arraycopy(interpolator.v[k], 0, v[k], 0, dimension); } vectorsInitialized = interpolator.vectorsInitialized; } } /** {@inheritDoc} */ @Override protected StepInterpolator doCopy() { return new DormandPrince853StepInterpolator(this); } /** {@inheritDoc} */ @Override public void reinitialize(final AbstractIntegrator integrator, final double[] y, final double[][] yDotK, final boolean forward) { super.reinitialize(integrator, y, yDotK, forward); final int dimension = currentState.length; yDotKLast = new double[3][]; for (int k = 0; k < yDotKLast.length; ++k) { yDotKLast[k] = new double[dimension]; } v = new double[7][]; for (int k = 0; k < v.length; ++k) { v[k] = new double[dimension]; } vectorsInitialized = false; } /** {@inheritDoc} */ @Override public void storeTime(final double t) { super.storeTime(t); vectorsInitialized = false; } /** {@inheritDoc} */ @Override protected void computeInterpolatedStateAndDerivatives(final double theta, final double oneMinusThetaH) throws DerivativeException { if (! vectorsInitialized) { if (v == null) { v = new double[7][]; for (int k = 0; k < 7; ++k) { v[k] = new double[interpolatedState.length]; } } // perform the last evaluations if they have not been done yet finalizeStep(); // compute the interpolation vectors for this time step for (int i = 0; i < interpolatedState.length; ++i) { final double yDot1 = yDotK[0][i]; final double yDot6 = yDotK[5][i]; final double yDot7 = yDotK[6][i]; final double yDot8 = yDotK[7][i]; final double yDot9 = yDotK[8][i]; final double yDot10 = yDotK[9][i]; final double yDot11 = yDotK[10][i]; final double yDot12 = yDotK[11][i]; final double yDot13 = yDotK[12][i]; final double yDot14 = yDotKLast[0][i];

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> final double yDot15 = yDotKLast[1][i]; final double yDot16 = yDotKLast[2][i]; v[0][i] = B_01 * yDot1 + B_06 * yDot6 + B_07 * yDot7 + B_08 * yDot8 + B_09 * yDot9 + B_10 * yDot10 + B_11 * yDot11 + B_12 * yDot12; v[1][i] = yDot1 - v[0][i]; v[2][i] = v[0][i] - v[1][i] - yDotK[12][i]; for (int k = 0; k < D.length; ++k) { v[k+3][i] = D[k][0] * yDot1 + D[k][1] * yDot6 + D[k][2] * yDot7 + D[k][3] * yDot8 + D[k][4] * yDot9 + D[k][5] * yDot10 + D[k][6] * yDot11 + D[k][7] * yDot12 + D[k][8] * yDot13 + D[k][9] * yDot14 + D[k][10] * yDot15 + D[k][11] * yDot16; } } vectorsInitialized = true; } final double eta = 1 - theta; final double twoTheta = 2 * theta; final double theta2 = theta * theta; final double dot1 = 1 - twoTheta; final double dot2 = theta * (2 - 3 * theta); final double dot3 = twoTheta * (1 + theta * (twoTheta -3)); final double dot4 = theta2 * (3 + theta * (5 * theta - 8)); final double dot5 = theta2 * (3 + theta * (-12 + theta * (15 - 6 * theta))); final double dot6 = theta2 * theta * (4 + theta * (-15 + theta * (18 - 7 * theta))); for (int i = 0; i < interpolatedState.length; ++i) { interpolatedState[i] = currentState[i] - oneMinusThetaH * (v[0][i] - theta * (v[1][i] + theta * (v[2][i] + eta * (v[3][i] + theta * (v[4][i] + eta * (v[5][i] + theta * (v[6][i]))))))); interpolatedDerivatives[i] =

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> v[0][i] + dot1 * v[1][i] + dot2 * v[2][i] + dot3 * v[3][i] + dot4 * v[4][i] + dot5 * v[5][i] + dot6 * v[6][i]; } } /** {@inheritDoc} */ @Override protected void doFinalize() throws DerivativeException { if (currentState == null) { // we are finalizing an uninitialized instance return; } double s; final double[] yTmp = new double[currentState.length]; // k14 for (int j = 0; j < currentState.length; ++j) { s = K14_01 * yDotK[0][j] + K14_06 * yDotK[5][j] + K14_07 * yDotK[6][j] + K14_08 * yDotK[7][j] + K14_09 * yDotK[8][j] + K14_10 * yDotK[9][j] + K14_11 * yDotK[10][j] + K14_12 * yDotK[11][j] + K14_13 * yDotK[12][j]; yTmp[j] = currentState[j] + h * s; } integrator.computeDerivatives(previousTime + C14 * h, yTmp, yDotKLast[0]); // k15 for (int j = 0; j < currentState.length; ++j) { s = K15_01 * yDotK[0][j] + K15_06 * yDotK[5][j] + K15_07 * yDotK[6][j] + K15_08 * yDotK[7][j] + K15_09 * yDotK[8][j] + K15_10 * yDotK[9][j] + K15_11 * yDotK[10][j] + K15_12 * yDotK[11][j] + K15_13 * yDotK[12][j] + K15_14 * yDotKLast[0][j]; yTmp[j] = currentState[j] + h * s; } integrator.computeDerivatives(previousTime + C15 * h, yTmp, yDotKLast[1]); // k16 for (int j = 0; j < currentState.length; ++j) { s = K16_01 * yDotK[0][j] + K

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>16_06 * yDotK[5][j] + K16_07 * yDotK[6][j] + K16_08 * yDotK[7][j] + K16_09 * yDotK[8][j] + K16_10 * yDotK[9][j] + K16_11 * yDotK[10][j] + K16_12 * yDotK[11][j] + K16_13 * yDotK[12][j] + K16_14 * yDotKLast[0][j] + K16_15 * yDotKLast[1][j]; yTmp[j] = currentState[j] + h * s; } integrator.computeDerivatives(previousTime + C16 * h, yTmp, yDotKLast[2]); } /** {@inheritDoc} */ @Override public void writeExternal(final ObjectOutput out) throws IOException { try { // save the local attributes finalizeStep(); } catch (DerivativeException e) { throw MathRuntimeException.createIOException(e); } final int dimension = (currentState == null) ? -1 : currentState.length; out.writeInt(dimension); for (int i = 0; i < dimension; ++i) { out.writeDouble(yDotKLast[0][i]); out.writeDouble(yDotKLast[1][i]); out.writeDouble(yDotKLast[2][i]); } // save the state of the base class super.writeExternal(out); } /** {@inheritDoc} */ @Override public void readExternal(final ObjectInput in) throws IOException { // read the local attributes yDotKLast = new double[3][]; final int dimension = in.readInt(); yDotKLast[0] = (dimension < 0) ? null : new double[dimension]; yDotKLast[1] = (dimension < 0) ? null : new double[dimension]; yDotKLast[2] = (dimension < 0) ? null : new double[dimension]; for (int i = 0; i < dimension; ++i) { yDotKLast[0][i] = in.readDouble(); yDotKLast[1][i] = in.readDouble(); yDotKLast[2][i] = in.readDouble(); } // read the base state super.readExternal(in); } }

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>epIntegrator(final String name, final int nSteps, final int order, final double minStep, final double maxStep, final double scalAbsoluteTolerance, final double scalRelativeTolerance) { super(name, minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); if (nSteps <= 0) { throw MathRuntimeException.createIllegalArgumentException( "{0} method needs at least one previous point", name); } starter = new DormandPrince853Integrator(minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); this.nSteps = nSteps; exp = -1.0 / order; // set the default values of the algorithm control parameters setSafety(0.9); setMinReduction(0.2); setMaxGrowth(Math.pow(2.0, -exp)); } /** * Build a multistep integrator with the given stepsize bounds. * <p>The default starter integrator is set to the {@link * DormandPrince853Integrator Dormand-Prince 8(5,3)} integrator with * some defaults settings.</p> * <p> * The default max growth factor is set to a quite low value: 2<sup>1/order</sup>. * </p> * @param name name of the method * @param nSteps number of steps of the multistep method * (excluding the one being computed) * @param order order of the method * @param minStep minimal step (must be positive even for backward * integration), the last step can be smaller than this * @param maxStep maximal step (must be positive even for backward * integration) * @param vecAbsoluteTolerance allowed absolute error * @param vecRelativeTolerance allowed relative error */ protected MultistepIntegrator(final String name, final int nSteps, final int order, final double minStep, final double maxStep, final double[] vecAbsoluteTolerance, final double[] vecRelativeTolerance) { super(name, minStep, maxStep, vecAbsoluteTolerance, vecRelativeTolerance); starter = new DormandPrince853Integrator(minStep, maxStep, vecAbsoluteTolerance, vecRelativeTolerance); this.nSteps = nSteps; exp = -1.0 / order; // set the default values of the algorithm control parameters setSafety(0.9); setMinReduction(0.2); setMaxGrowth(Math.pow(2.0, -exp)); } /** * Get the starter integrator. * @return starter integrator */ public ODEIntegrator getStarterIntegrator() { return starter; } /** * Set the starter integrator. * <p>The various step and event handlers for this starter integrator * will be managed automatically by the multi-

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> factor for stepsize control. * @param minReduction minimal reduction factor */ public void setMinReduction(final double minReduction) { this.minReduction = minReduction; } /** Get the maximal growth factor for stepsize control. * @return maximal growth factor */ public double getMaxGrowth() { return maxGrowth; } /** Set the maximal growth factor for stepsize control. * @param maxGrowth maximal growth factor */ public void setMaxGrowth(final double maxGrowth) { this.maxGrowth = maxGrowth; } /** Get the safety factor for stepsize control. * @return safety factor */ public double getSafety() { return safety; } /** Set the safety factor for stepsize control. * @param safety safety factor */ public void setSafety(final double safety) { this.safety = safety; } /** Compute step grow/shrink factor according to normalized error. * @param error normalized error of the current step * @return grow/shrink factor for next step */ protected double computeStepGrowShrinkFactor(final double error) { return Math.min(maxGrowth, Math.max(minReduction, safety * Math.pow(error, exp))); } /** Transformer used to convert the first step to Nordsieck representation. */ public static interface NordsieckTransformer { /** Initialize the high order scaled derivatives at step start. * @param first first scaled derivative at step start * @param multistep scaled derivatives after step start (hy'1, ..., hy'k-1) * will be modified * @return high order derivatives at step start */ RealMatrix initializeHighOrderDerivatives(double[] first, double[][] multistep); } /** Specialized step handler storing the first step. */ private class NordsieckInitializer implements StepHandler { /** Problem dimension. */ private final int n; /** Simple constructor. * @param n problem dimension */ public NordsieckInitializer(final int n) { this.n = n; } /** {@inheritDoc} */ public void handleStep(StepInterpolator interpolator, boolean isLast) throws DerivativeException { final double prev = interpolator.getPreviousTime(); final double curr = interpolator.getCurrentTime(); stepStart = prev; stepSize = (curr - prev) / (nSteps + 1); // compute the first scaled derivative interpolator.setInterpolatedTime(prev); scaled = interpolator.getInterpolatedDerivatives().clone(); for (int j = 0; j < n; ++j) { scaled[j] *= stepSize; } // compute the high order scaled derivatives final double[][] multistep = new double[nSteps][]; for (int i = 1; i <= nSteps; ++i) { interpolator.setInterpol

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>atedTime(prev + stepSize * i); final double[] msI = interpolator.getInterpolatedDerivatives().clone(); for (int j = 0; j < n; ++j) { msI[j] *= stepSize; } multistep[i - 1] = msI; } nordsieck = initializeHighOrderDerivatives(scaled, multistep); // stop the integrator after the first step has been handled throw new InitializationCompletedMarkerException(); } /** {@inheritDoc} */ public boolean requiresDenseOutput() { return true; } /** {@inheritDoc} */ public void reset() { // nothing to do } } /** Marker exception used ONLY to stop the starter integrator after first step. */ private static class InitializationCompletedMarkerException extends DerivativeException { /** Serializable version identifier. */ private static final long serialVersionUID = -4105805787353488365L; /** Simple constructor. */ public InitializationCompletedMarkerException() { super((Throwable) null); } } /** Wrapper for differential equations, ensuring start evaluations are counted. */ private class CountingDifferentialEquations implements FirstOrderDifferentialEquations { /** Dimension of the problem. */ private final int dimension; /** Simple constructor. * @param dimension dimension of the problem */ public CountingDifferentialEquations(final int dimension) { this.dimension = dimension; } /** {@inheritDoc} */ public void computeDerivatives(double t, double[] y, double[] dot) throws DerivativeException { MultistepIntegrator.this.computeDerivatives(t, y, dot); } /** {@inheritDoc} */ public int getDimension() { return dimension; } } }

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> to provide the array argument of the {@link * #BlockRealMatrix(int, int, double[][], boolean)} constructor. * </p> * @param rawData data array in raw layout * @return a new data array containing the same entries but in blocks layout * @exception IllegalArgumentException if <code>rawData</code> is not rectangular * (not all rows have the same length) * @see #createBlocksLayout(int, int) * @see #BlockRealMatrix(int, int, double[][], boolean) */ public static double[][] toBlocksLayout(final double[][] rawData) throws IllegalArgumentException { final int rows = rawData.length; final int columns = rawData[0].length; final int blockRows = (rows + BLOCK_SIZE - 1) / BLOCK_SIZE; final int blockColumns = (columns + BLOCK_SIZE - 1) / BLOCK_SIZE; // safety checks for (int i = 0; i < rawData.length; ++i) { final int length = rawData[i].length; if (length != columns) { throw MathRuntimeException.createIllegalArgumentException( "some rows have length {0} while others have length {1}", columns, length); } } // convert array final double[][] blocks = new double[blockRows * blockColumns][]; int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); final int iHeight = pEnd - pStart; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; final int qEnd = Math.min(qStart + BLOCK_SIZE, columns); final int jWidth = qEnd - qStart; // allocate new block final double[] block = new double[iHeight * jWidth]; blocks[blockIndex] = block; // copy data int index = 0; for (int p = pStart; p < pEnd; ++p) { System.arraycopy(rawData[p], qStart, block, index, jWidth); index += jWidth; } ++blockIndex; } } return blocks; } /** * Create a data array in blocks layout. * <p> * This method can be used to create the array argument of the {@link * #BlockRealMatrix(int, int, double[][], boolean)} constructor. * </p> * @param rows the number of rows in the new matrix * @param columns the number of columns in the new matrix * @return a new data array in blocks layout * @see #toBlocksLayout(

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>double[][]) * @see #BlockRealMatrix(int, int, double[][], boolean) */ public static double[][] createBlocksLayout(final int rows, final int columns) { final int blockRows = (rows + BLOCK_SIZE - 1) / BLOCK_SIZE; final int blockColumns = (columns + BLOCK_SIZE - 1) / BLOCK_SIZE; final double[][] blocks = new double[blockRows * blockColumns][]; int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); final int iHeight = pEnd - pStart; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; final int qEnd = Math.min(qStart + BLOCK_SIZE, columns); final int jWidth = qEnd - qStart; blocks[blockIndex] = new double[iHeight * jWidth]; ++blockIndex; } } return blocks; } /** {@inheritDoc} */ @Override public BlockRealMatrix createMatrix(final int rowDimension, final int columnDimension) throws IllegalArgumentException { return new BlockRealMatrix(rowDimension, columnDimension); } /** {@inheritDoc} */ @Override public BlockRealMatrix copy() { // create an empty matrix BlockRealMatrix copied = new BlockRealMatrix(rows, columns); // copy the blocks for (int i = 0; i < blocks.length; ++i) { System.arraycopy(blocks[i], 0, copied.blocks[i], 0, blocks[i].length); } return copied; } /** {@inheritDoc} */ @Override public BlockRealMatrix add(final RealMatrix m) throws IllegalArgumentException { try { return add((BlockRealMatrix) m); } catch (ClassCastException cce) { // safety check MatrixUtils.checkAdditionCompatible(this, m); final BlockRealMatrix out = new BlockRealMatrix(rows, columns); // perform addition block-wise, to ensure good cache behavior int blockIndex = 0; for (int iBlock = 0; iBlock < out.blockRows; ++iBlock) { for (int jBlock = 0; jBlock < out.blockColumns; ++jBlock) { // perform addition on the current block final double[] outBlock = out.blocks[blockIndex]; final double[] tBlock = blocks[blockIndex]; final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); final int qStart = jBlock * BLOCK_SIZE; final int

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> qEnd = Math.min(qStart + BLOCK_SIZE, columns); int k = 0; for (int p = pStart; p < pEnd; ++p) { for (int q = qStart; q < qEnd; ++q) { outBlock[k] = tBlock[k] + m.getEntry(p, q); ++k; } } // go to next block ++blockIndex; } } return out; } } /** * Compute the sum of this and <code>m</code>. * * @param m matrix to be added * @return this + m * @throws IllegalArgumentException if m is not the same size as this */ public BlockRealMatrix add(final BlockRealMatrix m) throws IllegalArgumentException { // safety check MatrixUtils.checkAdditionCompatible(this, m); final BlockRealMatrix out = new BlockRealMatrix(rows, columns); // perform addition block-wise, to ensure good cache behavior for (int blockIndex = 0; blockIndex < out.blocks.length; ++blockIndex) { final double[] outBlock = out.blocks[blockIndex]; final double[] tBlock = blocks[blockIndex]; final double[] mBlock = m.blocks[blockIndex]; for (int k = 0; k < outBlock.length; ++k) { outBlock[k] = tBlock[k] + mBlock[k]; } } return out; } /** {@inheritDoc} */ @Override public BlockRealMatrix subtract(final RealMatrix m) throws IllegalArgumentException { try { return subtract((BlockRealMatrix) m); } catch (ClassCastException cce) { // safety check MatrixUtils.checkSubtractionCompatible(this, m); final BlockRealMatrix out = new BlockRealMatrix(rows, columns); // perform subtraction block-wise, to ensure good cache behavior int blockIndex = 0; for (int iBlock = 0; iBlock < out.blockRows; ++iBlock) { for (int jBlock = 0; jBlock < out.blockColumns; ++jBlock) { // perform subtraction on the current block final double[] outBlock = out.blocks[blockIndex]; final double[] tBlock = blocks[blockIndex]; final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); final int qStart = jBlock * BLOCK_SIZE; final int qEnd = Math.min(qStart + BLOCK_SIZE, columns); int k = 0; for (int p = pStart; p < pEnd; ++p) { for (int q = qStart; q < qEnd; ++q) { outBlock[k] = tBlock

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>, m.getColumnDimension()); // perform multiplication block-wise, to ensure good cache behavior int blockIndex = 0; for (int iBlock = 0; iBlock < out.blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < out.blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; final int qEnd = Math.min(qStart + BLOCK_SIZE, m.getColumnDimension()); // select current block final double[] outBlock = out.blocks[blockIndex]; // perform multiplication on current block for (int kBlock = 0; kBlock < blockColumns; ++kBlock) { final int kWidth = blockWidth(kBlock); final double[] tBlock = blocks[iBlock * blockColumns + kBlock]; final int rStart = kBlock * BLOCK_SIZE; int k = 0; for (int p = pStart; p < pEnd; ++p) { final int lStart = (p - pStart) * kWidth; final int lEnd = lStart + kWidth; for (int q = qStart; q < qEnd; ++q) { double sum = 0; int r = rStart; for (int l = lStart; l < lEnd; ++l) { sum += tBlock[l] * m.getEntry(r, q); ++r; } outBlock[k] += sum; ++k; } } } // go to next block ++blockIndex; } } return out; } } /** * Returns the result of postmultiplying this by m. * * @param m matrix to postmultiply by * @return this * m * @throws IllegalArgumentException * if columnDimension(this) != rowDimension(m) */ public BlockRealMatrix multiply(BlockRealMatrix m) throws IllegalArgumentException { // safety check MatrixUtils.checkMultiplicationCompatible(this, m); final BlockRealMatrix out = new BlockRealMatrix(rows, m.columns); // perform multiplication block-wise, to ensure good cache behavior int blockIndex = 0; for (int iBlock = 0; iBlock < out.blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < out.blockColumns; ++jBlock) { final int jWidth = out.blockWidth(jBlock); final int jWidth2 = jWidth + jWidth; final int jWidth3 = jWidth2 + j

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>Width; final int jWidth4 = jWidth3 + jWidth; // select current block final double[] outBlock = out.blocks[blockIndex]; // perform multiplication on current block for (int kBlock = 0; kBlock < blockColumns; ++kBlock) { final int kWidth = blockWidth(kBlock); final double[] tBlock = blocks[iBlock * blockColumns + kBlock]; final double[] mBlock = m.blocks[kBlock * m.blockColumns + jBlock]; int k = 0; for (int p = pStart; p < pEnd; ++p) { final int lStart = (p - pStart) * kWidth; final int lEnd = lStart + kWidth; for (int nStart = 0; nStart < jWidth; ++nStart) { double sum = 0; int l = lStart; int n = nStart; while (l < lEnd - 3) { sum += tBlock[l] * mBlock[n] + tBlock[l + 1] * mBlock[n + jWidth] + tBlock[l + 2] * mBlock[n + jWidth2] + tBlock[l + 3] * mBlock[n + jWidth3]; l += 4; n += jWidth4; } while (l < lEnd) { sum += tBlock[l++] * mBlock[n]; n += jWidth; } outBlock[k] += sum; ++k; } } } // go to next block ++blockIndex; } } return out; } /** {@inheritDoc} */ @Override public double[][] getData() { final double[][] data = new double[getRowDimension()][getColumnDimension()]; final int lastColumns = columns - (blockColumns - 1) * BLOCK_SIZE; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); int regularPos = 0; int lastPos = 0; for (int p = pStart; p < pEnd; ++p) { final double[] dataP = data[p]; int blockIndex = iBlock * blockColumns; int dataPos = 0; for (int jBlock = 0; jBlock < blockColumns - 1; ++jBlock) { System.arraycopy(blocks[blockIndex++], regularPos, dataP, dataPos, BLOCK_SIZE); dataPos += BLOCK_SIZE; } System.arraycopy(blocks[blockIndex], lastPos, dataP, dataPos, lastColumns); regularPos += BLOCK_SIZE; lastPos += lastColumns;

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> } } return data; } /** {@inheritDoc} */ @Override public double getNorm() { final double[] colSums = new double[BLOCK_SIZE]; double maxColSum = 0; for (int jBlock = 0; jBlock < blockColumns; jBlock++) { final int jWidth = blockWidth(jBlock); Arrays.fill(colSums, 0, jWidth, 0.0); for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int iHeight = blockHeight(iBlock); final double[] block = blocks[iBlock * blockColumns + jBlock]; for (int j = 0; j < jWidth; ++j) { double sum = 0; for (int i = 0; i < iHeight; ++i) { sum += Math.abs(block[i * jWidth + j]); } colSums[j] += sum; } } for (int j = 0; j < jWidth; ++j) { maxColSum = Math.max(maxColSum, colSums[j]); } } return maxColSum; } /** {@inheritDoc} */ @Override public double getFrobeniusNorm() { double sum2 = 0; for (int blockIndex = 0; blockIndex < blocks.length; ++blockIndex) { for (final double entry : blocks[blockIndex]) { sum2 += entry * entry; } } return Math.sqrt(sum2); } /** {@inheritDoc} */ @Override public BlockRealMatrix getSubMatrix(final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException { // safety checks MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn); // create the output matrix final BlockRealMatrix out = new BlockRealMatrix(endRow - startRow + 1, endColumn - startColumn + 1); // compute blocks shifts final int blockStartRow = startRow / BLOCK_SIZE; final int rowsShift = startRow % BLOCK_SIZE; final int blockStartColumn = startColumn / BLOCK_SIZE; final int columnsShift = startColumn % BLOCK_SIZE; // perform extraction block-wise, to ensure good cache behavior int pBlock = blockStartRow; for (int iBlock = 0; iBlock < out.blockRows; ++iBlock) { final int iHeight = out.blockHeight(iBlock); int qBlock = blockStartColumn; for (int jBlock = 0; jBlock < out.blockColumns; ++jBlock) { final int jWidth = out.blockWidth(jBlock); // handle one block of the output matrix final int

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> final int blockEndColumn = (endColumn + BLOCK_SIZE) / BLOCK_SIZE; // perform copy block-wise, to ensure good cache behavior for (int iBlock = blockStartRow; iBlock < blockEndRow; ++iBlock) { final int iHeight = blockHeight(iBlock); final int firstRow = iBlock * BLOCK_SIZE; final int iStart = Math.max(row, firstRow); final int iEnd = Math.min(endRow + 1, firstRow + iHeight); for (int jBlock = blockStartColumn; jBlock < blockEndColumn; ++jBlock) { final int jWidth = blockWidth(jBlock); final int firstColumn = jBlock * BLOCK_SIZE; final int jStart = Math.max(column, firstColumn); final int jEnd = Math.min(endColumn + 1, firstColumn + jWidth); final int jLength = jEnd - jStart; // handle one block, row by row final double[] block = blocks[iBlock * blockColumns + jBlock]; for (int i = iStart; i < iEnd; ++i) { System.arraycopy(subMatrix[i - row], jStart - column, block, (i - firstRow) * jWidth + (jStart - firstColumn), jLength); } } } } /** {@inheritDoc} */ @Override public BlockRealMatrix getRowMatrix(final int row) throws MatrixIndexException { MatrixUtils.checkRowIndex(this, row); final BlockRealMatrix out = new BlockRealMatrix(1, columns); // perform copy block-wise, to ensure good cache behavior final int iBlock = row / BLOCK_SIZE; final int iRow = row - iBlock * BLOCK_SIZE; int outBlockIndex = 0; int outIndex = 0; double[] outBlock = out.blocks[outBlockIndex]; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int jWidth = blockWidth(jBlock); final double[] block = blocks[iBlock * blockColumns + jBlock]; final int available = outBlock.length - outIndex; if (jWidth > available) { System.arraycopy(block, iRow * jWidth, outBlock, outIndex, available); outBlock = out.blocks[++outBlockIndex]; System.arraycopy(block, iRow * jWidth, outBlock, 0, jWidth - available); outIndex = jWidth - available; } else { System.arraycopy(block, iRow * jWidth, outBlock, outIndex, jWidth); outIndex += jWidth; } } return out; } /** {@inheritDoc} */ @Override public void setRowMatrix(final int row, final RealMatrix

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> int outIndex = 0; double[] outBlock = out.blocks[outBlockIndex]; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int iHeight = blockHeight(iBlock); final double[] block = blocks[iBlock * blockColumns + jBlock]; for (int i = 0; i < iHeight; ++i) { if (outIndex >= outBlock.length) { outBlock = out.blocks[++outBlockIndex]; outIndex = 0; } outBlock[outIndex++] = block[i * jWidth + jColumn]; } } return out; } /** {@inheritDoc} */ @Override public void setColumnMatrix(final int column, final RealMatrix matrix) throws MatrixIndexException, InvalidMatrixException { try { setColumnMatrix(column, (BlockRealMatrix) matrix); } catch (ClassCastException cce) { super.setColumnMatrix(column, matrix); } } /** * Sets the entries in column number <code>column</code> * as a column matrix. Column indices start at 0. * * @param column the column to be set * @param matrix column matrix (must have one column and the same number of rows * as the instance) * @throws MatrixIndexException if the specified column index is invalid * @throws InvalidMatrixException if the matrix dimensions do not match one * instance column */ void setColumnMatrix(final int column, final BlockRealMatrix matrix) throws MatrixIndexException, InvalidMatrixException { MatrixUtils.checkColumnIndex(this, column); final int nRows = getRowDimension(); if ((matrix.getRowDimension() != nRows) || (matrix.getColumnDimension() != 1)) { throw new InvalidMatrixException( "dimensions mismatch: got {0}x{1} but expected {2}x{3}", matrix.getRowDimension(), matrix.getColumnDimension(), nRows, 1); } // perform copy block-wise, to ensure good cache behavior final int jBlock = column / BLOCK_SIZE; final int jColumn = column - jBlock * BLOCK_SIZE; final int jWidth = blockWidth(jBlock); int mBlockIndex = 0; int mIndex = 0; double[] mBlock = matrix.blocks[mBlockIndex]; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int iHeight = blockHeight(iBlock); final double[] block = blocks[iBlock * blockColumns + jBlock]; for (int i = 0; i < iHeight; ++i) { if (mIndex >= mBlock.length) { mBlock = matrix.blocks[++mBlockIndex]; mIndex = 0; } block[i * jWidth + jColumn]

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> = mBlock[mIndex++]; } } } /** {@inheritDoc} */ @Override public RealVector getRowVector(final int row) throws MatrixIndexException { MatrixUtils.checkRowIndex(this, row); final double[] outData = new double[columns]; // perform copy block-wise, to ensure good cache behavior final int iBlock = row / BLOCK_SIZE; final int iRow = row - iBlock * BLOCK_SIZE; int outIndex = 0; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int jWidth = blockWidth(jBlock); final double[] block = blocks[iBlock * blockColumns + jBlock]; System.arraycopy(block, iRow * jWidth, outData, outIndex, jWidth); outIndex += jWidth; } return new ArrayRealVector(outData, false); } /** {@inheritDoc} */ @Override public void setRowVector(final int row, final RealVector vector) throws MatrixIndexException, InvalidMatrixException { try { setRow(row, ((ArrayRealVector) vector).getDataRef()); } catch (ClassCastException cce) { super.setRowVector(row, vector); } } /** {@inheritDoc} */ @Override public RealVector getColumnVector(final int column) throws MatrixIndexException { MatrixUtils.checkColumnIndex(this, column); final double[] outData = new double[rows]; // perform copy block-wise, to ensure good cache behavior final int jBlock = column / BLOCK_SIZE; final int jColumn = column - jBlock * BLOCK_SIZE; final int jWidth = blockWidth(jBlock); int outIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int iHeight = blockHeight(iBlock); final double[] block = blocks[iBlock * blockColumns + jBlock]; for (int i = 0; i < iHeight; ++i) { outData[outIndex++] = block[i * jWidth + jColumn]; } } return new ArrayRealVector(outData, false); } /** {@inheritDoc} */ @Override public void setColumnVector(final int column, final RealVector vector) throws MatrixIndexException, InvalidMatrixException { try { setColumn(column, ((ArrayRealVector) vector).getDataRef()); } catch (ClassCastException cce) { super.setColumnVector(column, vector); } } /** {@inheritDoc} */ @Override public double[] getRow(final int row) throws MatrixIndexException { MatrixUtils.checkRowIndex(this, row); final double[] out = new double[columns]; // perform copy block-wise, to ensure good cache behavior final int iBlock

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> = row / BLOCK_SIZE; final int iRow = row - iBlock * BLOCK_SIZE; int outIndex = 0; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int jWidth = blockWidth(jBlock); final double[] block = blocks[iBlock * blockColumns + jBlock]; System.arraycopy(block, iRow * jWidth, out, outIndex, jWidth); outIndex += jWidth; } return out; } /** {@inheritDoc} */ @Override public void setRow(final int row, final double[] array) throws MatrixIndexException, InvalidMatrixException { MatrixUtils.checkRowIndex(this, row); final int nCols = getColumnDimension(); if (array.length != nCols) { throw new InvalidMatrixException( "dimensions mismatch: got {0}x{1} but expected {2}x{3}", 1, array.length, 1, nCols); } // perform copy block-wise, to ensure good cache behavior final int iBlock = row / BLOCK_SIZE; final int iRow = row - iBlock * BLOCK_SIZE; int outIndex = 0; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int jWidth = blockWidth(jBlock); final double[] block = blocks[iBlock * blockColumns + jBlock]; System.arraycopy(array, outIndex, block, iRow * jWidth, jWidth); outIndex += jWidth; } } /** {@inheritDoc} */ @Override public double[] getColumn(final int column) throws MatrixIndexException { MatrixUtils.checkColumnIndex(this, column); final double[] out = new double[rows]; // perform copy block-wise, to ensure good cache behavior final int jBlock = column / BLOCK_SIZE; final int jColumn = column - jBlock * BLOCK_SIZE; final int jWidth = blockWidth(jBlock); int outIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int iHeight = blockHeight(iBlock); final double[] block = blocks[iBlock * blockColumns + jBlock]; for (int i = 0; i < iHeight; ++i) { out[outIndex++] = block[i * jWidth + jColumn]; } } return out; } /** {@inheritDoc} */ @Override public void setColumn(final int column, final double[] array) throws MatrixIndexException, InvalidMatrixException { MatrixUtils.checkColumnIndex(this, column); final int nRows = getRowDimension(); if (array.length != nRows) { throw new InvalidMatrixException( "dimensions mismatch: got {

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>0}x{1} but expected {2}x{3}", array.length, 1, nRows, 1); } // perform copy block-wise, to ensure good cache behavior final int jBlock = column / BLOCK_SIZE; final int jColumn = column - jBlock * BLOCK_SIZE; final int jWidth = blockWidth(jBlock); int outIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int iHeight = blockHeight(iBlock); final double[] block = blocks[iBlock * blockColumns + jBlock]; for (int i = 0; i < iHeight; ++i) { block[i * jWidth + jColumn] = array[outIndex++]; } } } /** {@inheritDoc} */ @Override public double getEntry(final int row, final int column) throws MatrixIndexException { try { final int iBlock = row / BLOCK_SIZE; final int jBlock = column / BLOCK_SIZE; final int k = (row - iBlock * BLOCK_SIZE) * blockWidth(jBlock) + (column - jBlock * BLOCK_SIZE); return blocks[iBlock * blockColumns + jBlock][k]; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( "no entry at indices ({0}, {1}) in a {2}x{3} matrix", row, column, getRowDimension(), getColumnDimension()); } } /** {@inheritDoc} */ @Override public void setEntry(final int row, final int column, final double value) throws MatrixIndexException { try { final int iBlock = row / BLOCK_SIZE; final int jBlock = column / BLOCK_SIZE; final int k = (row - iBlock * BLOCK_SIZE) * blockWidth(jBlock) + (column - jBlock * BLOCK_SIZE); blocks[iBlock * blockColumns + jBlock][k] = value; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( "no entry at indices ({0}, {1}) in a {2}x{3} matrix", row, column, getRowDimension(), getColumnDimension()); } } /** {@inheritDoc} */ @Override public void addToEntry(final int row, final int column, final double increment) throws MatrixIndexException { try { final int iBlock = row / BLOCK_SIZE; final int jBlock = column / BLOCK_SIZE; final int k = (row - iBlock * BLOCK_SIZE) * blockWidth(jBlock) + (column - jBlock * BLOCK_SIZE); blocks[iBlock * blockColumns + jBlock][k] += increment; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( "no

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> entry at indices ({0}, {1}) in a {2}x{3} matrix", row, column, getRowDimension(), getColumnDimension()); } } /** {@inheritDoc} */ @Override public void multiplyEntry(final int row, final int column, final double factor) throws MatrixIndexException { try { final int iBlock = row / BLOCK_SIZE; final int jBlock = column / BLOCK_SIZE; final int k = (row - iBlock * BLOCK_SIZE) * blockWidth(jBlock) + (column - jBlock * BLOCK_SIZE); blocks[iBlock * blockColumns + jBlock][k] *= factor; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( "no entry at indices ({0}, {1}) in a {2}x{3} matrix", row, column, getRowDimension(), getColumnDimension()); } } /** {@inheritDoc} */ @Override public BlockRealMatrix transpose() { final int nRows = getRowDimension(); final int nCols = getColumnDimension(); final BlockRealMatrix out = new BlockRealMatrix(nCols, nRows); // perform transpose block-wise, to ensure good cache behavior int blockIndex = 0; for (int iBlock = 0; iBlock < blockColumns; ++iBlock) { for (int jBlock = 0; jBlock < blockRows; ++jBlock) { // transpose current block final double[] outBlock = out.blocks[blockIndex]; final double[] tBlock = blocks[jBlock * blockColumns + iBlock]; final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, columns); final int qStart = jBlock * BLOCK_SIZE; final int qEnd = Math.min(qStart + BLOCK_SIZE, rows); int k = 0; for (int p = pStart; p < pEnd; ++p) { final int lInc = pEnd - pStart; int l = p - pStart; for (int q = qStart; q < qEnd; ++q) { outBlock[k] = tBlock[l]; ++k; l+= lInc; } } // go to next block ++blockIndex; } } return out; } /** {@inheritDoc} */ @Override public int getRowDimension() { return rows; } /** {@inheritDoc} */ @Override public int getColumnDimension() { return columns; } /** {@inheritDoc} */ @Override public double[] operate(final double[] v) throws IllegalArgumentException { if (v.length != columns) { throw MathRuntimeException.createIllegalArgumentException( "vector length mismatch: got {0} but expected {1}", v.

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>length, columns); } final double[] out = new double[rows]; // perform multiplication block-wise, to ensure good cache behavior for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final double[] block = blocks[iBlock * blockColumns + jBlock]; final int qStart = jBlock * BLOCK_SIZE; final int qEnd = Math.min(qStart + BLOCK_SIZE, columns); int k = 0; for (int p = pStart; p < pEnd; ++p) { double sum = 0; int q = qStart; while (q < qEnd - 3) { sum += block[k] * v[q] + block[k + 1] * v[q + 1] + block[k + 2] * v[q + 2] + block[k + 3] * v[q + 3]; k += 4; q += 4; } while (q < qEnd) { sum += block[k++] * v[q++]; } out[p] += sum; } } } return out; } /** {@inheritDoc} */ @Override public double[] preMultiply(final double[] v) throws IllegalArgumentException { if (v.length != rows) { throw MathRuntimeException.createIllegalArgumentException( "vector length mismatch: got {0} but expected {1}", v.length, rows); } final double[] out = new double[columns]; // perform multiplication block-wise, to ensure good cache behavior for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int jWidth = blockWidth(jBlock); final int jWidth2 = jWidth + jWidth; final int jWidth3 = jWidth2 + jWidth; final int jWidth4 = jWidth3 + jWidth; final int qStart = jBlock * BLOCK_SIZE; final int qEnd = Math.min(qStart + BLOCK_SIZE, columns); for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final double[] block = blocks[iBlock * blockColumns + jBlock]; final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); for (int q = qStart; q < qEnd; ++q) { int k = q - qStart; double sum = 0; int p = pStart; while (p < p

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>End - 3) { sum += block[k] * v[p] + block[k + jWidth] * v[p + 1] + block[k + jWidth2] * v[p + 2] + block[k + jWidth3] * v[p + 3]; k += jWidth4; p += 4; } while (p < pEnd) { sum += block[k] * v[p++]; k += jWidth; } out[q] += sum; } } } return out; } /** {@inheritDoc} */ @Override public double walkInRowOrder(final RealMatrixChangingVisitor visitor) throws MatrixVisitorException { visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); for (int p = pStart; p < pEnd; ++p) { for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int jWidth = blockWidth(jBlock); final int qStart = jBlock * BLOCK_SIZE; final int qEnd = Math.min(qStart + BLOCK_SIZE, columns); final double[] block = blocks[iBlock * blockColumns + jBlock]; int k = (p - pStart) * jWidth; for (int q = qStart; q < qEnd; ++q) { block[k] = visitor.visit(p, q, block[k]); ++k; } } } } return visitor.end(); } /** {@inheritDoc} */ @Override public double walkInRowOrder(final RealMatrixPreservingVisitor visitor) throws MatrixVisitorException { visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); for (int p = pStart; p < pEnd; ++p) { for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int jWidth = blockWidth(jBlock); final int qStart = jBlock * BLOCK_SIZE; final int qEnd = Math.min(qStart + BLOCK_SIZE, columns); final double[] block = blocks[iBlock * blockColumns + jBlock]; int k = (p - pStart) * jWidth; for (int q = qStart;

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> q < qEnd; ++q) { visitor.visit(p, q, block[k]); ++k; } } } } return visitor.end(); } /** {@inheritDoc} */ @Override public double walkInRowOrder(final RealMatrixChangingVisitor visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException, MatrixVisitorException { MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn); visitor.start(rows, columns, startRow, endRow, startColumn, endColumn); for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) { final int p0 = iBlock * BLOCK_SIZE; final int pStart = Math.max(startRow, p0); final int pEnd = Math.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); for (int p = pStart; p < pEnd; ++p) { for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) { final int jWidth = blockWidth(jBlock); final int q0 = jBlock * BLOCK_SIZE; final int qStart = Math.max(startColumn, q0); final int qEnd = Math.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); final double[] block = blocks[iBlock * blockColumns + jBlock]; int k = (p - p0) * jWidth + qStart - q0; for (int q = qStart; q < qEnd; ++q) { block[k] = visitor.visit(p, q, block[k]); ++k; } } } } return visitor.end(); } /** {@inheritDoc} */ @Override public double walkInRowOrder(final RealMatrixPreservingVisitor visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException, MatrixVisitorException { MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn); visitor.start(rows, columns, startRow, endRow, startColumn, endColumn); for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) { final int p0 = iBlock * BLOCK_SIZE; final int pStart = Math.max(startRow, p0); final int pEnd = Math.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); for (int p = pStart; p < pEnd; ++p

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>) { for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) { final int jWidth = blockWidth(jBlock); final int q0 = jBlock * BLOCK_SIZE; final int qStart = Math.max(startColumn, q0); final int qEnd = Math.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); final double[] block = blocks[iBlock * blockColumns + jBlock]; int k = (p - p0) * jWidth + qStart - q0; for (int q = qStart; q < qEnd; ++q) { visitor.visit(p, q, block[k]); ++k; } } } } return visitor.end(); } /** {@inheritDoc} */ @Override public double walkInOptimizedOrder(final RealMatrixChangingVisitor visitor) throws MatrixVisitorException { visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; final int qEnd = Math.min(qStart + BLOCK_SIZE, columns); final double[] block = blocks[blockIndex]; int k = 0; for (int p = pStart; p < pEnd; ++p) { for (int q = qStart; q < qEnd; ++q) { block[k] = visitor.visit(p, q, block[k]); ++k; } } ++blockIndex; } } return visitor.end(); } /** {@inheritDoc} */ @Override public double walkInOptimizedOrder(final RealMatrixPreservingVisitor visitor) throws MatrixVisitorException { visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; final int qEnd = Math.min(qStart + BLOCK_SIZE, columns); final double[] block = blocks[blockIndex]; int k = 0;

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> for (int p = pStart; p < pEnd; ++p) { for (int q = qStart; q < qEnd; ++q) { visitor.visit(p, q, block[k]); ++k; } } ++blockIndex; } } return visitor.end(); } /** {@inheritDoc} */ @Override public double walkInOptimizedOrder(final RealMatrixChangingVisitor visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException, MatrixVisitorException { MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn); visitor.start(rows, columns, startRow, endRow, startColumn, endColumn); for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) { final int p0 = iBlock * BLOCK_SIZE; final int pStart = Math.max(startRow, p0); final int pEnd = Math.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) { final int jWidth = blockWidth(jBlock); final int q0 = jBlock * BLOCK_SIZE; final int qStart = Math.max(startColumn, q0); final int qEnd = Math.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); final double[] block = blocks[iBlock * blockColumns + jBlock]; for (int p = pStart; p < pEnd; ++p) { int k = (p - p0) * jWidth + qStart - q0; for (int q = qStart; q < qEnd; ++q) { block[k] = visitor.visit(p, q, block[k]); ++k; } } } } return visitor.end(); } /** {@inheritDoc} */ @Override public double walkInOptimizedOrder(final RealMatrixPreservingVisitor visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException, MatrixVisitorException { MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn); visitor.start(rows, columns, startRow, endRow, startColumn, endColumn); for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) { final int p0 = iBlock * BLOCK_SIZE; final int pStart = Math.max(startRow, p0); final int pEnd = Math.min

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>((iBlock + 1) * BLOCK_SIZE, 1 + endRow); for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) { final int jWidth = blockWidth(jBlock); final int q0 = jBlock * BLOCK_SIZE; final int qStart = Math.max(startColumn, q0); final int qEnd = Math.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); final double[] block = blocks[iBlock * blockColumns + jBlock]; for (int p = pStart; p < pEnd; ++p) { int k = (p - p0) * jWidth + qStart - q0; for (int q = qStart; q < qEnd; ++q) { visitor.visit(p, q, block[k]); ++k; } } } } return visitor.end(); } /** * Get the height of a block. * @param blockRow row index (in block sense) of the block * @return height (number of rows) of the block */ private int blockHeight(final int blockRow) { return (blockRow == blockRows - 1) ? rows - blockRow * BLOCK_SIZE : BLOCK_SIZE; } /** * Get the width of a block. * @param blockColumn column index (in block sense) of the block * @return width (number of columns) of the block */ private int blockWidth(final int blockColumn) { return (blockColumn == blockColumns - 1) ? columns - blockColumn * BLOCK_SIZE : BLOCK_SIZE; } }

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>; double r0 = value; long a0 = (long) Math.floor(r0); if (a0 > overflow) { throw new FractionConversionException(value, a0, 1l); } // check for (almost) integer arguments, which should not go // to iterations. if (Math.abs(a0 - value) < epsilon) { numerator = BigInteger.valueOf(a0); denominator = BigInteger.ONE; return; } long p0 = 1; long q0 = 0; long p1 = a0; long q1 = 1; long p2 = 0; long q2 = 1; int n = 0; boolean stop = false; do { ++n; final double r1 = 1.0 / (r0 - a0); final long a1 = (long) Math.floor(r1); p2 = (a1 * p1) + p0; q2 = (a1 * q1) + q0; if ((p2 > overflow) || (q2 > overflow)) { throw new FractionConversionException(value, p2, q2); } final double convergent = (double) p2 / (double) q2; if ((n < maxIterations) && (Math.abs(convergent - value) > epsilon) && (q2 < maxDenominator)) { p0 = p1; p1 = p2; q0 = q1; q1 = q2; a0 = a1; r0 = r1; } else { stop = true; } } while (!stop); if (n >= maxIterations) { throw new FractionConversionException(value, maxIterations); } if (q2 < maxDenominator) { numerator = BigInteger.valueOf(p2); denominator = BigInteger.valueOf(q2); } else { numerator = BigInteger.valueOf(p1); denominator = BigInteger.valueOf(q1); } } /** * Create a fraction given the double value and maximum denominator. * <p> * References: * <ul> * <li><a href="http://mathworld.wolfram.com/ContinuedFraction.html"> * Continued Fraction</a> equations (11) and (22)-(26)</li> * </ul> * </p> * * @param value * the double value to convert to a fraction. * @param maxDenominator * The maximum allowed value for denominator. * @throws FractionConversionException * if the continued fraction failed to converge. */ public BigFraction(final double value, final int maxDenominator) throws FractionConversionException { this(value, 0, maxDenominator, 100);

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> } /** * <p> * Create a {@link BigFraction} equivalent to the passed <tt>int</tt>, ie * "num / 1". * </p> * * @param num * the numerator. */ public BigFraction(final int num) { this(BigInteger.valueOf(num), BigInteger.ONE); } /** * <p> * Create a {@link BigFraction} given the numerator and denominator as simple * <tt>int</tt>. The {@link BigFraction} is reduced to lowest terms. * </p> * * @param num * the numerator. * @param den * the denominator. */ public BigFraction(final int num, final int den) { this(BigInteger.valueOf(num), BigInteger.valueOf(den)); } /** * <p> * Create a {@link BigFraction} equivalent to the passed long, ie "num / 1". * </p> * * @param num * the numerator. */ public BigFraction(final long num) { this(BigInteger.valueOf(num), BigInteger.ONE); } /** * <p> * Create a {@link BigFraction} given the numerator and denominator as simple * <tt>long</tt>. The {@link BigFraction} is reduced to lowest terms. * </p> * * @param num * the numerator. * @param den * the denominator. */ public BigFraction(final long num, final long den) { this(BigInteger.valueOf(num), BigInteger.valueOf(den)); } /** * <p> * Creates a <code>BigFraction</code> instance with the 2 parts of a fraction * Y/Z. * </p> * * <p> * Any negative signs are resolved to be on the numerator. * </p> * * @param numerator * the numerator, for example the three in 'three sevenths'. * @param denominator * the denominator, for example the seven in 'three sevenths'. * @return a new fraction instance, with the numerator and denominator * reduced. * @throws ArithmeticException * if the denominator is <code>zero</code>. */ public static BigFraction getReducedFraction(final int numerator, final int denominator) { if (numerator == 0) { return ZERO; // normalize zero. } return new BigFraction(numerator, denominator); } /** * <p> * Returns the absolute value of this {@link BigFraction}. * </p> * * @return the absolute value as a {@link BigFraction}. */ public BigFraction abs() { return (BigInteger.ZERO.compareTo(numerator) <= 0) ? this

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> : negate(); } /** * <p> * Adds the value of this fraction to the passed {@link BigInteger}, * returning the result in reduced form. * </p> * * @param bg * the {@link BigInteger} to add, must'nt be <code>null</code>. * @return a <code>BigFraction</code> instance with the resulting values. * @throws NullPointerException * if the {@link BigInteger} is <code>null</code>. */ public BigFraction add(final BigInteger bg) { return new BigFraction(numerator.add(denominator.multiply(bg)), denominator); } /** * <p> * Adds the value of this fraction to the passed <tt>integer</tt>, returning * the result in reduced form. * </p> * * @param i * the <tt>integer</tt> to add. * @return a <code>BigFraction</code> instance with the resulting values. */ public BigFraction add(final int i) { return add(BigInteger.valueOf(i)); } /** * <p> * Adds the value of this fraction to the passed <tt>long</tt>, returning * the result in reduced form. * </p> * * @param l * the <tt>long</tt> to add. * @return a <code>BigFraction</code> instance with the resulting values. */ public BigFraction add(final long l) { return add(BigInteger.valueOf(l)); } /** * <p> * Adds the value of this fraction to another, returning the result in * reduced form. * </p> * * @param fraction * the {@link BigFraction} to add, must not be <code>null</code>. * @return a {@link BigFraction} instance with the resulting values. * @throws NullPointerException * if the {@link BigFraction} is <code>null</code>. */ public BigFraction add(final BigFraction fraction) { if (ZERO.equals(fraction)) { return this; } BigInteger num = null; BigInteger den = null; if (denominator.equals(fraction.denominator)) { num = numerator.add(fraction.numerator); den = denominator; } else { num = (numerator.multiply(fraction.denominator)).add((fraction.numerator).multiply(denominator)); den = denominator.multiply(fraction.denominator); } return new BigFraction(num, den); } /** * <p> * Gets the fraction as a <code>BigDecimal</code>. This calculates the * fraction as the numerator divided by denominator. * </p> * * @return the fraction as a <code>BigDecimal</code>. * @throws ArithmeticException * if

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>BigInteger</code> is <code>null</code>. * @throws ArithmeticException * if the fraction to divide by is zero. */ public BigFraction divide(final BigInteger bg) { if (BigInteger.ZERO.equals(bg)) { throw MathRuntimeException.createArithmeticException(FORBIDDEN_ZERO_DENOMINATOR); } return new BigFraction(numerator, denominator.multiply(bg)); } /** * <p> * Divide the value of this fraction by the passed <tt>int</tt>, ie * "this * 1 / i", returning the result in reduced form. * </p> * * @param i * the <tt>int</tt> to divide by. * @return a {@link BigFraction} instance with the resulting values. * @throws ArithmeticException * if the fraction to divide by is zero. */ public BigFraction divide(final int i) { return divide(BigInteger.valueOf(i)); } /** * <p> * Divide the value of this fraction by the passed <tt>long</tt>, ie * "this * 1 / l", returning the result in reduced form. * </p> * * @param l * the <tt>long</tt> to divide by. * @return a {@link BigFraction} instance with the resulting values. * @throws ArithmeticException * if the fraction to divide by is zero. */ public BigFraction divide(final long l) { return divide(BigInteger.valueOf(l)); } /** * <p> * Divide the value of this fraction by another, returning the result in * reduced form. * </p> * * @param fraction * the fraction to divide by, must not be <code>null</code>. * @return a {@link BigFraction} instance with the resulting values. * @throws NullPointerException * if the fraction is <code>null</code>. * @throws ArithmeticException * if the fraction to divide by is zero. */ public BigFraction divide(final BigFraction fraction) { if (BigInteger.ZERO.equals(fraction.numerator)) { throw MathRuntimeException.createArithmeticException(FORBIDDEN_ZERO_DENOMINATOR); } return multiply(fraction.reciprocal()); } /** * <p> * Gets the fraction as a <tt>double</tt>. This calculates the fraction as * the numerator divided by denominator. * </p> * * @return the fraction as a <tt>double</tt> * @see java.lang.Number#doubleValue() */ @Override public double doubleValue() { return numerator.doubleValue() / denominator.doubleValue(); } /** * <p> * Test for the equality of two fractions. If the lowest term numerator and * denom

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> <tt>long</tt>. * </p> * * @return the numerator as a <tt>long</tt>. */ public long getNumeratorAsLong() { return numerator.longValue(); } /** * <p> * Gets a hashCode for the fraction. * </p> * * @return a hash code value for this object. * @see java.lang.Object#hashCode() */ @Override public int hashCode() { return 37 * (37 * 17 + numerator.hashCode()) + denominator.hashCode(); } /** * <p> * Gets the fraction as an <tt>int</tt>. This returns the whole number part * of the fraction. * </p> * * @return the whole number fraction part. * @see java.lang.Number#intValue() */ @Override public int intValue() { return numerator.divide(denominator).intValue(); } /** * <p> * Gets the fraction as a <tt>long</tt>. This returns the whole number part * of the fraction. * </p> * * @return the whole number fraction part. * @see java.lang.Number#longValue() */ @Override public long longValue() { return numerator.divide(denominator).longValue(); } /** * <p> * Multiplies the value of this fraction by the passed * <code>BigInteger</code>, returning the result in reduced form. * </p> * * @param bg * the <code>BigInteger</code> to multiply by. * @return a <code>BigFraction</code> instance with the resulting values. * @throws NullPointerException * if the bg is <code>null</code>. */ public BigFraction multiply(final BigInteger bg) { return new BigFraction(bg.multiply(numerator), denominator); } /** * <p> * Multiply the value of this fraction by the passed <tt>int</tt>, returning * the result in reduced form. * </p> * * @param i * the <tt>int</tt> to multiply by. * @return a {@link BigFraction} instance with the resulting values. */ public BigFraction multiply(final int i) { return multiply(BigInteger.valueOf(i)); } /** * <p> * Multiply the value of this fraction by the passed <tt>long</tt>, * returning the result in reduced form. * </p> * * @param l * the <tt>long</tt> to multiply by. * @return a {@link BigFraction} instance with the resulting values. */ public BigFraction multiply(final long l) { return multiply(BigInteger.valueOf(l)); } /** * <p>

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> return new BigFraction(MathUtils.pow(numerator, exponent), MathUtils.pow(denominator, exponent)); } /** * <p> * Returns a <code>BigFraction</code> whose value is * <tt>(this<sup>exponent</sup>)</tt>, returning the result in reduced form. * </p> * * @param exponent * exponent to which this <code>BigFraction</code> is to be raised. * @return <tt>this<sup>exponent</sup></tt> as a <code>BigFraction</code>. */ public BigFraction pow(final BigInteger exponent) { if (exponent.compareTo(BigInteger.ZERO) < 0) { final BigInteger eNeg = exponent.negate(); return new BigFraction(MathUtils.pow(denominator, eNeg), MathUtils.pow(numerator, eNeg)); } return new BigFraction(MathUtils.pow(numerator, exponent), MathUtils.pow(denominator, exponent)); } /** * <p> * Returns a <code>double</code> whose value is * <tt>(this<sup>exponent</sup>)</tt>, returning the result in reduced form. * </p> * * @param exponent * exponent to which this <code>BigFraction</code> is to be raised. * @return <tt>this<sup>exponent</sup></tt>. */ public double pow(final double exponent) { return Math.pow(numerator.doubleValue(), exponent) / Math.pow(denominator.doubleValue(), exponent); } /** * <p> * Return the multiplicative inverse of this fraction. * </p> * * @return the reciprocal fraction. */ public BigFraction reciprocal() { return new BigFraction(denominator, numerator); } /** * <p> * Reduce this <code>BigFraction</code> to its lowest terms. * </p> * * @return the reduced <code>BigFraction</code>. It doesn't change anything if * the fraction can be reduced. */ public BigFraction reduce() { final BigInteger gcd = numerator.gcd(denominator); return new BigFraction(numerator.divide(gcd), denominator.divide(gcd)); } /** * <p> * Subtracts the value of an {@link BigInteger} from the value of this one, * returning the result in reduced form. * </p> * * @param bg * the {@link BigInteger} to subtract, must'nt be * <code>null</code>. * @return a <code>BigFraction</code> instance with the resulting values. * @throws NullPointerException * if the {@link BigInteger} is <code>null</code>. */ public Big

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>Fraction subtract(final BigInteger bg) { return new BigFraction(numerator.subtract(denominator.multiply(bg)), denominator); } /** * <p> * Subtracts the value of an <tt>integer</tt> from the value of this one, * returning the result in reduced form. * </p> * * @param i * the <tt>integer</tt> to subtract. * @return a <code>BigFraction</code> instance with the resulting values. */ public BigFraction subtract(final int i) { return subtract(BigInteger.valueOf(i)); } /** * <p> * Subtracts the value of an <tt>integer</tt> from the value of this one, * returning the result in reduced form. * </p> * * @param l * the <tt>long</tt> to subtract. * @return a <code>BigFraction</code> instance with the resulting values, or * this object if the <tt>long</tt> is zero. */ public BigFraction subtract(final long l) { return subtract(BigInteger.valueOf(l)); } /** * <p> * Subtracts the value of another fraction from the value of this one, * returning the result in reduced form. * </p> * * @param fraction * the {@link BigFraction} to subtract, must not be * <code>null</code>. * @return a {@link BigFraction} instance with the resulting values * @throws NullPointerException * if the fraction is <code>null</code>. */ public BigFraction subtract(final BigFraction fraction) { if (ZERO.equals(fraction)) { return this; } BigInteger num = null; BigInteger den = null; if (denominator.equals(fraction.denominator)) { num = numerator.subtract(fraction.numerator); den = denominator; } else { num = (numerator.multiply(fraction.denominator)).subtract((fraction.numerator).multiply(denominator)); den = denominator.multiply(fraction.denominator); } return new BigFraction(num, den); } /** * <p> * Returns the <code>String</code> representing this fraction, ie * "num / dem" or just "num" if the denominator is one. * </p> * * @return a string representation of the fraction. * @see java.lang.Object#toString() */ @Override public String toString() { String str = null; if (BigInteger.ONE.equals(denominator)) { str = numerator.toString(); } else if (BigInteger.ZERO.equals(numerator)) { str = "0"; } else { str = numerator + " / " + denominator; } return str; }

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> : yDotK.length; out.writeInt(kMax); for (int k = 0; k < kMax; ++k) { for (int i = 0; i < n; ++i) { out.writeDouble(yDotK[k][i]); } } // we do not save any reference to the equations } /** {@inheritDoc} */ @Override public void readExternal(final ObjectInput in) throws IOException { // read the base class final double t = readBaseExternal(in); // read the local attributes final int n = (currentState == null) ? -1 : currentState.length; final int kMax = in.readInt(); yDotK = (kMax < 0) ? null : new double[kMax][]; for (int k = 0; k < kMax; ++k) { yDotK[k] = (n < 0) ? null : new double[n]; for (int i = 0; i < n; ++i) { yDotK[k][i] = in.readDouble(); } } integrator = null; if (currentState != null) { // we can now set the interpolated time and state setInterpolatedTime(t); } else { interpolatedTime = t; } } }

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> input array is copied, not referenced.</p> * @param <T> the type of the field elements * @param data input array * @return RealMatrix containing the values of the array * @throws IllegalArgumentException if <code>data</code> is not rectangular * (not all rows have the same length) or empty * @throws NullPointerException if either <code>data</code> or * <code>data[0]</code> is null * @see #createFieldMatrix(Field, int, int) * @since 2.0 */ public static <T extends FieldElement<T>> FieldMatrix<T> createFieldMatrix(T[][] data) { return (data.length * data[0].length <= 4096) ? new Array2DRowFieldMatrix<T>(data) : new BlockFieldMatrix<T>(data); } /** * Returns <code>dimension x dimension</code> identity matrix. * * @param dimension dimension of identity matrix to generate * @return identity matrix * @throws IllegalArgumentException if dimension is not positive * @since 1.1 */ public static RealMatrix createRealIdentityMatrix(int dimension) { final RealMatrix m = createRealMatrix(dimension, dimension); for (int i = 0; i < dimension; ++i) { m.setEntry(i, i, 1.0); } return m; } /** * Returns <code>dimension x dimension</code> identity matrix. * * @param <T> the type of the field elements * @param field field to which the elements belong * @param dimension dimension of identity matrix to generate * @return identity matrix * @throws IllegalArgumentException if dimension is not positive * @since 2.0 */ public static <T extends FieldElement<T>> FieldMatrix<T> createFieldIdentityMatrix(final Field<T> field, final int dimension) { final T zero = field.getZero(); final T one = field.getOne(); @SuppressWarnings("unchecked") // zero is type T final T[][] d = (T[][]) Array.newInstance(zero.getClass(), new int[] { dimension, dimension }); for (int row = 0; row < dimension; row++) { final T[] dRow = d[row]; Arrays.fill(dRow, zero); dRow[row] = one; } return new Array2DRowFieldMatrix<T>(d, false); } /** * Returns <code>dimension x dimension</code> identity matrix. * * @param dimension dimension of identity matrix to generate * @return identity matrix * @throws IllegalArgumentException if dimension is not positive * @since 1.1 * @deprecated since 2.0, replaced by {@link #createFieldIdentityMatrix(Field, int)} */ @Deprecated public static BigMatrix createBigIdentityMatrix(int

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> dimension) { final BigDecimal[][] d = new BigDecimal[dimension][dimension]; for (int row = 0; row < dimension; row++) { final BigDecimal[] dRow = d[row]; Arrays.fill(dRow, BigMatrixImpl.ZERO); dRow[row] = BigMatrixImpl.ONE; } return new BigMatrixImpl(d, false); } /** * Returns a diagonal matrix with specified elements. * * @param diagonal diagonal elements of the matrix (the array elements * will be copied) * @return diagonal matrix * @since 2.0 */ public static RealMatrix createRealDiagonalMatrix(final double[] diagonal) { final RealMatrix m = createRealMatrix(diagonal.length, diagonal.length); for (int i = 0; i < diagonal.length; ++i) { m.setEntry(i, i, diagonal[i]); } return m; } /** * Returns a diagonal matrix with specified elements. * * @param <T> the type of the field elements * @param diagonal diagonal elements of the matrix (the array elements * will be copied) * @return diagonal matrix * @since 2.0 */ public static <T extends FieldElement<T>> FieldMatrix<T> createFieldDiagonalMatrix(final T[] diagonal) { final FieldMatrix<T> m = createFieldMatrix(diagonal[0].getField(), diagonal.length, diagonal.length); for (int i = 0; i < diagonal.length; ++i) { m.setEntry(i, i, diagonal[i]); } return m; } /** * Returns a {@link BigMatrix} whose entries are the the values in the * the input array. The input array is copied, not referenced. * * @param data input array * @return RealMatrix containing the values of the array * @throws IllegalArgumentException if <code>data</code> is not rectangular * (not all rows have the same length) or empty * @throws NullPointerException if data is null * @deprecated since 2.0 replaced by {@link #createFieldMatrix(FieldElement[][])} */ @Deprecated public static BigMatrix createBigMatrix(double[][] data) { return new BigMatrixImpl(data); } /** * Returns a {@link BigMatrix} whose entries are the the values in the * the input array. The input array is copied, not referenced. * * @param data input array * @return RealMatrix containing the values of the array * @throws IllegalArgumentException if <code>data</code> is not rectangular * (not all rows have the same length) or empty * @throws NullPointerException if data is null * @deprecated since 2.0 replaced by {@link #createFieldMatrix(FieldElement[][])} */ @Deprecated public static BigMatrix

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>, true); } /** * Creates a row {@link RealMatrix} using the data from the input * array. * * @param rowData the input row data * @return a 1 x rowData.length RealMatrix * @throws IllegalArgumentException if <code>rowData</code> is empty * @throws NullPointerException if <code>rowData</code>is null */ public static RealMatrix createRowRealMatrix(double[] rowData) { final int nCols = rowData.length; final RealMatrix m = createRealMatrix(1, nCols); for (int i = 0; i < nCols; ++i) { m.setEntry(0, i, rowData[i]); } return m; } /** * Creates a row {@link FieldMatrix} using the data from the input * array. * * @param <T> the type of the field elements * @param rowData the input row data * @return a 1 x rowData.length FieldMatrix * @throws IllegalArgumentException if <code>rowData</code> is empty * @throws NullPointerException if <code>rowData</code>is null */ public static <T extends FieldElement<T>> FieldMatrix<T> createRowFieldMatrix(final T[] rowData) { final int nCols = rowData.length; if (nCols == 0) { throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column"); } final FieldMatrix<T> m = createFieldMatrix(rowData[0].getField(), 1, nCols); for (int i = 0; i < nCols; ++i) { m.setEntry(0, i, rowData[i]); } return m; } /** * Creates a row {@link BigMatrix} using the data from the input * array. * * @param rowData the input row data * @return a 1 x rowData.length BigMatrix * @throws IllegalArgumentException if <code>rowData</code> is empty * @throws NullPointerException if <code>rowData</code>is null * @deprecated since 2.0 replaced by {@link #createRowFieldMatrix(FieldElement[])} */ @Deprecated public static BigMatrix createRowBigMatrix(double[] rowData) { final int nCols = rowData.length; final BigDecimal[][] data = new BigDecimal[1][nCols]; for (int i = 0; i < nCols; ++i) { data[0][i] = new BigDecimal(rowData[i]); } return new BigMatrixImpl(data, false); } /** * Creates a row {@link BigMatrix} using the data from the input * array. * * @param rowData the input row data * @return a 1 x rowData.length BigMatrix * @throws IllegalArgumentException if <code>rowData</code> is

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> empty * @throws NullPointerException if <code>rowData</code>is null * @deprecated since 2.0 replaced by {@link #createRowFieldMatrix(FieldElement[])} */ @Deprecated public static BigMatrix createRowBigMatrix(BigDecimal[] rowData) { final int nCols = rowData.length; final BigDecimal[][] data = new BigDecimal[1][nCols]; System.arraycopy(rowData, 0, data[0], 0, nCols); return new BigMatrixImpl(data, false); } /** * Creates a row {@link BigMatrix} using the data from the input * array. * * @param rowData the input row data * @return a 1 x rowData.length BigMatrix * @throws IllegalArgumentException if <code>rowData</code> is empty * @throws NullPointerException if <code>rowData</code>is null * @deprecated since 2.0 replaced by {@link #createRowFieldMatrix(FieldElement[])} */ @Deprecated public static BigMatrix createRowBigMatrix(String[] rowData) { final int nCols = rowData.length; final BigDecimal[][] data = new BigDecimal[1][nCols]; for (int i = 0; i < nCols; ++i) { data[0][i] = new BigDecimal(rowData[i]); } return new BigMatrixImpl(data, false); } /** * Creates a column {@link RealMatrix} using the data from the input * array. * * @param columnData the input column data * @return a columnData x 1 RealMatrix * @throws IllegalArgumentException if <code>columnData</code> is empty * @throws NullPointerException if <code>columnData</code>is null */ public static RealMatrix createColumnRealMatrix(double[] columnData) { final int nRows = columnData.length; final RealMatrix m = createRealMatrix(nRows, 1); for (int i = 0; i < nRows; ++i) { m.setEntry(i, 0, columnData[i]); } return m; } /** * Creates a column {@link FieldMatrix} using the data from the input * array. * * @param <T> the type of the field elements * @param columnData the input column data * @return a columnData x 1 FieldMatrix * @throws IllegalArgumentException if <code>columnData</code> is empty * @throws NullPointerException if <code>columnData</code>is null */ public static <T extends FieldElement<T>> FieldMatrix<T> createColumnFieldMatrix(final T[] columnData) { final int nRows = columnData.length; if (nRows == 0) { throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row"); } final FieldMatrix<T> m = createField

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>Matrix(columnData[0].getField(), nRows, 1); for (int i = 0; i < nRows; ++i) { m.setEntry(i, 0, columnData[i]); } return m; } /** * Creates a column {@link BigMatrix} using the data from the input * array. * * @param columnData the input column data * @return a columnData x 1 BigMatrix * @throws IllegalArgumentException if <code>columnData</code> is empty * @throws NullPointerException if <code>columnData</code>is null * @deprecated since 2.0 replaced by {@link #createColumnFieldMatrix(FieldElement[])} */ @Deprecated public static BigMatrix createColumnBigMatrix(double[] columnData) { final int nRows = columnData.length; final BigDecimal[][] data = new BigDecimal[nRows][1]; for (int row = 0; row < nRows; row++) { data[row][0] = new BigDecimal(columnData[row]); } return new BigMatrixImpl(data, false); } /** * Creates a column {@link BigMatrix} using the data from the input * array. * * @param columnData the input column data * @return a columnData x 1 BigMatrix * @throws IllegalArgumentException if <code>columnData</code> is empty * @throws NullPointerException if <code>columnData</code>is null * @deprecated since 2.0 replaced by {@link #createColumnFieldMatrix(FieldElement[])} */ @Deprecated public static BigMatrix createColumnBigMatrix(BigDecimal[] columnData) { final int nRows = columnData.length; final BigDecimal[][] data = new BigDecimal[nRows][1]; for (int row = 0; row < nRows; row++) { data[row][0] = columnData[row]; } return new BigMatrixImpl(data, false); } /** * Creates a column {@link BigMatrix} using the data from the input * array. * * @param columnData the input column data * @return a columnData x 1 BigMatrix * @throws IllegalArgumentException if <code>columnData</code> is empty * @throws NullPointerException if <code>columnData</code>is null * @deprecated since 2.0 replaced by {@link #createColumnFieldMatrix(FieldElement[])} */ @Deprecated public static BigMatrix createColumnBigMatrix(String[] columnData) { int nRows = columnData.length; final BigDecimal[][] data = new BigDecimal[nRows][1]; for (int row = 0; row < nRows; row++) { data[row][0] = new BigDecimal(columnData[row]); } return new BigMatrixImpl(data, false); } /** * Check if a row index is valid

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> { * oos.defaultWriteObject(); // takes care of name field * MatrixUtils.serializeRealVector(coefficients, oos); * } * * private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException { * ois.defaultReadObject(); // takes care of name field * MatrixUtils.deserializeRealVector(this, "coefficients", ois); * } * * } * </code></pre> * </p> * * @param vector real vector to serialize * @param oos stream where the real vector should be written * @exception IOException if object cannot be written to stream * @see #deserializeRealVector(Object, String, ObjectInputStream) */ public static void serializeRealVector(final RealVector vector, final ObjectOutputStream oos) throws IOException { final int n = vector.getDimension(); oos.writeInt(n); for (int i = 0; i < n; ++i) { oos.writeDouble(vector.getEntry(i)); } } /** Deserialize a {@link RealVector} field in a class. * <p> * This method is intended to be called from within a private * <code>readObject</code> method (after a call to * <code>ois.defaultReadObject()</code>) in a class that has a * {@link RealVector} field, which should be declared <code>transient</code>. * This way, the default handling does not deserialize the vector (the {@link * RealVector} interface is not serializable by default) but this method does * deserialize it specifically. * </p> * @param instance instance in which the field must be set up * @param fieldName name of the field within the class (may be private and final) * @param ois stream from which the real vector should be read * @exception ClassNotFoundException if a class in the stream cannot be found * @exception IOException if object cannot be read from the stream * @see #serializeRealVector(RealVector, ObjectOutputStream) */ public static void deserializeRealVector(final Object instance, final String fieldName, final ObjectInputStream ois) throws ClassNotFoundException, IOException { try { // read the vector data final int n = ois.readInt(); final double[] data = new double[n]; for (int i = 0; i < n; ++i) { data[i] = ois.readDouble(); } // create the instance final RealVector vector = new ArrayRealVector(data, false); // set up the field final java.lang.reflect.Field f = instance.getClass().getDeclaredField(fieldName); f.setAccessible(true); f.set(instance, vector); } catch (NoSuchFieldException nsfe) { IOException ioe = new IOException(); ioe.

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>initCause(nsfe); throw ioe; } catch (IllegalAccessException iae) { IOException ioe = new IOException(); ioe.initCause(iae); throw ioe; } } /** Serialize a {@link RealMatrix}. * <p> * This method is intended to be called from within a private * <code>writeObject</code> method (after a call to * <code>oos.defaultWriteObject()</code>) in a class that has a * {@link RealMatrix} field, which should be declared <code>transient</code>. * This way, the default handling does not serialize the matrix (the {@link * RealMatrix} interface is not serializable by default) but this method does * serialize it specifically. * </p> * <p> * The following example shows how a simple class with a name and a real matrix * should be written: * <pre><code> * public class NamedMatrix implements Serializable { * * private final String name; * private final transient RealMatrix coefficients; * * // omitted constructors, getters ... * * private void writeObject(ObjectOutputStream oos) throws IOException { * oos.defaultWriteObject(); // takes care of name field * MatrixUtils.serializeRealMatrix(coefficients, oos); * } * * private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException { * ois.defaultReadObject(); // takes care of name field * MatrixUtils.deserializeRealMatrix(this, "coefficients", ois); * } * * } * </code></pre> * </p> * * @param matrix real matrix to serialize * @param oos stream where the real matrix should be written * @exception IOException if object cannot be written to stream * @see #deserializeRealMatrix(Object, String, ObjectInputStream) */ public static void serializeRealMatrix(final RealMatrix matrix, final ObjectOutputStream oos) throws IOException { final int n = matrix.getRowDimension(); final int m = matrix.getColumnDimension(); oos.writeInt(n); oos.writeInt(m); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { oos.writeDouble(matrix.getEntry(i, j)); } } } /** Deserialize a {@link RealMatrix} field in a class. * <p> * This method is intended to be called from within a private * <code>readObject</code> method (after a call to * <code>ois.defaultReadObject()</code>) in a class that has a * {@link RealMatrix} field, which should be declared <code>transient</code>. * This way, the default handling does

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> not deserialize the matrix (the {@link * RealMatrix} interface is not serializable by default) but this method does * deserialize it specifically. * </p> * @param instance instance in which the field must be set up * @param fieldName name of the field within the class (may be private and final) * @param ois stream from which the real matrix should be read * @exception ClassNotFoundException if a class in the stream cannot be found * @exception IOException if object cannot be read from the stream * @see #serializeRealMatrix(RealMatrix, ObjectOutputStream) */ public static void deserializeRealMatrix(final Object instance, final String fieldName, final ObjectInputStream ois) throws ClassNotFoundException, IOException { try { // read the matrix data final int n = ois.readInt(); final int m = ois.readInt(); final double[][] data = new double[n][m]; for (int i = 0; i < n; ++i) { final double[] dataI = data[i]; for (int j = 0; j < m; ++j) { dataI[j] = ois.readDouble(); } } // create the instance final RealMatrix matrix = new Array2DRowRealMatrix(data, false); // set up the field final java.lang.reflect.Field f = instance.getClass().getDeclaredField(fieldName); f.setAccessible(true); f.set(instance, matrix); } catch (NoSuchFieldException nsfe) { IOException ioe = new IOException(); ioe.initCause(nsfe); throw ioe; } catch (IllegalAccessException iae) { IOException ioe = new IOException(); ioe.initCause(iae); throw ioe; } } }

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>ckTransformer(final int nSteps) { // compute exact coefficients FieldMatrix<BigFraction> bigP = buildP(nSteps); FieldDecompositionSolver<BigFraction> pSolver = new FieldLUDecompositionImpl<BigFraction>(bigP).getSolver(); BigFraction[] u = new BigFraction[nSteps]; Arrays.fill(u, BigFraction.ONE); BigFraction[] bigC1 = pSolver.solve(u); // update coefficients are computed by combining transform from // Nordsieck to multistep, then shifting rows to represent step advance // then applying inverse transform BigFraction[][] shiftedP = bigP.getData(); for (int i = shiftedP.length - 1; i > 0; --i) { // shift rows shiftedP[i] = shiftedP[i - 1]; } shiftedP[0] = new BigFraction[nSteps]; Arrays.fill(shiftedP[0], BigFraction.ZERO); FieldMatrix<BigFraction> bigMSupdate = pSolver.solve(new Array2DRowFieldMatrix<BigFraction>(shiftedP, false)); // initialization coefficients, computed from a R matrix = abs(P) bigP.walkInOptimizedOrder(new DefaultFieldMatrixChangingVisitor<BigFraction>(BigFraction.ZERO) { /** {@inheritDoc} */ @Override public BigFraction visit(int row, int column, BigFraction value) { return ((column & 0x1) == 0x1) ? value : value.negate(); } }); FieldMatrix<BigFraction> bigRInverse = new FieldLUDecompositionImpl<BigFraction>(bigP).getSolver().getInverse(); // convert coefficients to double initialization = MatrixUtils.bigFractionMatrixToRealMatrix(bigRInverse); update = MatrixUtils.bigFractionMatrixToRealMatrix(bigMSupdate); c1 = new double[nSteps]; for (int i = 0; i < nSteps; ++i) { c1[i] = bigC1[i].doubleValue(); } } /** Get the Nordsieck transformer for a given number of steps. * @param nSteps number of steps of the multistep method * (excluding the one being computed) * @return Nordsieck transformer for the specified number of steps */ public static AdamsNordsieckTransformer getInstance(final int nSteps) { synchronized(CACHE) { AdamsNordsieckTransformer t = CACHE.get(nSteps); if (t == null) { t = new AdamsNordsieckTransformer(nSteps); CACHE.put(nSteps, t); } return t; } } /** Get the number of steps of the method * (excluding the one being computed). * @return number of steps of the method * (excluding the one being computed)

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> */ public int getNSteps() { return c1.length; } /** Build the P matrix. * <p>The P matrix general terms are shifted j (-i)<sup>j-1</sup> terms: * <pre> * [ -2 3 -4 5 ... ] * [ -4 12 -32 80 ... ] * P = [ -6 27 -108 405 ... ] * [ -8 48 -256 1280 ... ] * [ ... ] * </pre></p> * @param nSteps number of steps of the multistep method * (excluding the one being computed) * @return P matrix */ private FieldMatrix<BigFraction> buildP(final int nSteps) { final BigFraction[][] pData = new BigFraction[nSteps][nSteps]; for (int i = 0; i < pData.length; ++i) { // build the P matrix elements from Taylor series formulas final BigFraction[] pI = pData[i]; final int factor = -(i + 1); int aj = factor; for (int j = 0; j < pI.length; ++j) { pI[j] = new BigFraction(aj * (j + 2)); aj *= factor; } } return new Array2DRowFieldMatrix<BigFraction>(pData, false); } /** Initialize the high order scaled derivatives at step start. * @param first first scaled derivative at step start * @param multistep scaled derivatives after step start (hy'1, ..., hy'k-1) * will be modified * @return high order derivatives at step start */ public Array2DRowRealMatrix initializeHighOrderDerivatives(final double[] first, final double[][] multistep) { for (int i = 0; i < multistep.length; ++i) { final double[] msI = multistep[i]; for (int j = 0; j < first.length; ++j) { msI[j] -= first[j]; } } return initialization.multiply(new Array2DRowRealMatrix(multistep, false)); } /** Update the high order scaled derivatives for Adams integrators (phase 1). * <p>The complete update of high order derivatives has a form similar to: * <pre> * r<sub>n+1</sub> = (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u + P<sup>-1</sup> A P r<sub>n</sub> * </pre> * this method computes the P<sup>-

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>1</sup> A P r<sub>n</sub> part.</p> * @param highOrder high order scaled derivatives * (h<sup>2</sup>/2 y'', ... h<sup>k</sup>/k! y(k)) * @return updated high order derivatives * @see #updateHighOrderDerivativesPhase2(double[], double[], Array2DRowRealMatrix) */ public Array2DRowRealMatrix updateHighOrderDerivativesPhase1(final Array2DRowRealMatrix highOrder) { return update.multiply(highOrder); } /** Update the high order scaled derivatives Adams integrators (phase 2). * <p>The complete update of high order derivatives has a form similar to: * <pre> * r<sub>n+1</sub> = (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u + P<sup>-1</sup> A P r<sub>n</sub> * </pre> * this method computes the (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u part.</p> * <p>Phase 1 of the update must already have been performed.</p> * @param start first order scaled derivatives at step start * @param end first order scaled derivatives at step end * @param highOrder high order scaled derivatives, will be modified * (h<sup>2</sup>/2 y'', ... h<sup>k</sup>/k! y(k)) * @see #updateHighOrderDerivativesPhase1(Array2DRowRealMatrix) */ public void updateHighOrderDerivativesPhase2(final double[] start, final double[] end, final Array2DRowRealMatrix highOrder) { final double[][] data = highOrder.getDataRef(); for (int i = 0; i < data.length; ++i) { final double[] dataI = data[i]; final double c1I = c1[i]; for (int j = 0; j < dataI.length; ++j) { dataI[j] += c1I * (start[j] - end[j]); } } } }

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> t0 * @param t target time for the integration * @param y placeholder where to put the state vector * @exception IntegratorException if some inconsistency is detected */ protected void sanityChecks(final FirstOrderDifferentialEquations ode, final double t0, final double[] y0, final double t, final double[] y) throws IntegratorException { if (ode.getDimension() != y0.length) { throw new IntegratorException( "dimensions mismatch: ODE problem has dimension {0}," + " initial state vector has dimension {1}", ode.getDimension(), y0.length); } if (ode.getDimension() != y.length) { throw new IntegratorException( "dimensions mismatch: ODE problem has dimension {0}," + " final state vector has dimension {1}", ode.getDimension(), y.length); } if (Math.abs(t - t0) <= 1.0e-12 * Math.max(Math.abs(t0), Math.abs(t))) { throw new IntegratorException( "too small integration interval: length = {0}", Math.abs(t - t0)); } } /** Add an event handler for end time checking. * <p>This method can be used to simplify handling of integration end time. * It leverages the nominal stop condition with the exceptional stop * conditions.</p> * @param startTime integration start time * @param endTime desired end time * @param manager manager containing the user-defined handlers * @return a new manager containing all the user-defined handlers plus a * dedicated manager triggering a stop event at entTime */ protected CombinedEventsManager addEndTimeChecker(final double startTime, final double endTime, final CombinedEventsManager manager) { CombinedEventsManager newManager = new CombinedEventsManager(); for (final EventState state : manager.getEventsStates()) { newManager.addEventHandler(state.getEventHandler(), state.getMaxCheckInterval(), state.getConvergence(), state.getMaxIterationCount()); } newManager.addEventHandler(new EndTimeChecker(endTime), Double.POSITIVE_INFINITY, Math.ulp(Math.max(Math.abs(startTime), Math.abs(endTime))), 100); return newManager; } /** Specialized event handler to stop integration. */ private static class EndTimeChecker implements EventHandler { /** Desired end time. */ private final double endTime; /** Build an instance. * @param endTime desired time */ public EndTimeChecker(final double endTime) { this.endTime = endTime; } /** {@inheritDoc} */ public int eventOccurred(double t, double[] y, boolean increasing) { return STOP; } /** {@inheritDoc} */ public double g(double t, double[] y) { return t - endTime;

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> for (int i = 0; i < scaled.length; ++i) { scaled[i] *= ratio; } final double[][] nData = nordsieck.getDataRef(); double power = ratio; for (int i = 0; i < nData.length; ++i) { power *= ratio; final double[] nDataI = nData[i]; for (int j = 0; j < nDataI.length; ++j) { nDataI[j] *= power; } } scalingH = stepSize; } /** * Get the state vector variation from current to interpolated state. * <p>This method is aimed at computing y(t<sub>interpolation</sub>) * -y(t<sub>current</sub>) accurately by avoiding the cancellation errors * that would occur if the subtraction were performed explicitly.</p> * <p>The returned vector is a reference to a reused array, so * it should not be modified and it should be copied if it needs * to be preserved across several calls.</p> * @return state vector at time {@link #getInterpolatedTime} * @see #getInterpolatedDerivatives() * @throws DerivativeException if this call induces an automatic * step finalization that throws one */ public double[] getInterpolatedStateVariation() throws DerivativeException { // compute and ignore interpolated state // to make sure state variation is computed as a side effect getInterpolatedState(); return stateVariation; } /** {@inheritDoc} */ @Override protected void computeInterpolatedStateAndDerivatives(final double theta, final double oneMinusThetaH) { final double x = interpolatedTime - referenceTime; final double normalizedAbscissa = x / scalingH; Arrays.fill(stateVariation, 0.0); Arrays.fill(interpolatedDerivatives, 0.0); // apply Taylor formula from high order to low order, // for the sake of numerical accuracy final double[][] nData = nordsieck.getDataRef(); for (int i = nData.length - 1; i >= 0; --i) { final int order = i + 2; final double[] nDataI = nData[i]; final double power = Math.pow(normalizedAbscissa, order); for (int j = 0; j < nDataI.length; ++j) { final double d = nDataI[j] * power; stateVariation[j] += d; interpolatedDerivatives[j] += order * d; } } for (int j = 0; j < currentState.length; ++j) { stateVariation[j] += scaled[j] * normalizedAbscissa; interpolatedState[j] = currentState[j] + stateVariation[j]; interpolatedDerivatives

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> the step. * The default implementation of this method does nothing. * @throws DerivativeException this exception is propagated to the * caller if the underlying user function triggers one */ protected void doFinalize() throws DerivativeException { } /** {@inheritDoc} */ public abstract void writeExternal(ObjectOutput out) throws IOException; /** {@inheritDoc} */ public abstract void readExternal(ObjectInput in) throws IOException, ClassNotFoundException; /** Save the base state of the instance. * This method performs step finalization if it has not been done * before. * @param out stream where to save the state * @exception IOException in case of write error */ protected void writeBaseExternal(final ObjectOutput out) throws IOException { if (currentState == null) { out.writeInt(-1); } else { out.writeInt(currentState.length); } out.writeDouble(previousTime); out.writeDouble(currentTime); out.writeDouble(h); out.writeBoolean(forward); if (currentState != null) { for (int i = 0; i < currentState.length; ++i) { out.writeDouble(currentState[i]); } } out.writeDouble(interpolatedTime); // we do not store the interpolated state, // it will be recomputed as needed after reading // finalize the step (and don't bother saving the now true flag) try { finalizeStep(); } catch (DerivativeException e) { throw MathRuntimeException.createIOException(e); } } /** Read the base state of the instance. * This method does <strong>neither</strong> set the interpolated * time nor state. It is up to the derived class to reset it * properly calling the {@link #setInterpolatedTime} method later, * once all rest of the object state has been set up properly. * @param in stream where to read the state from * @return interpolated time be set later by the caller * @exception IOException in case of read error */ protected double readBaseExternal(final ObjectInput in) throws IOException { final int dimension = in.readInt(); previousTime = in.readDouble(); currentTime = in.readDouble(); h = in.readDouble(); forward = in.readBoolean(); dirtyState = true; if (dimension < 0) { currentState = null; } else { currentState = new double[dimension]; for (int i = 0; i < currentState.length; ++i) { currentState[i] = in.readDouble(); } } // we do NOT handle the interpolated time and state here interpolatedTime = Double.NaN; interpolatedState = (dimension < 0) ? null : new double[dimension]; interpolatedDerivatives = (dimension < 0) ? null : new double[dimension

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> * @param <T> the type of the field elements * @param d data array * @return field to which array elements belong * @exception IllegalArgumentException if array is empty */ protected static <T extends FieldElement<T>> Field<T> extractField(final T[][] d) throws IllegalArgumentException { if (d.length == 0) { throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row"); } if (d[0].length == 0) { throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column"); } return d[0][0].getField(); } /** * Get the elements type from an array. * @param <T> the type of the field elements * @param d data array * @return field to which array elements belong * @exception IllegalArgumentException if array is empty */ protected static <T extends FieldElement<T>> Field<T> extractField(final T[] d) throws IllegalArgumentException { if (d.length == 0) { throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row"); } return d[0].getField(); } /** Build an array of elements. * <p> * Complete arrays are filled with field.getZero() * </p> * @param <T> the type of the field elements * @param field field to which array elements belong * @param rows number of rows * @param columns number of columns (may be negative to build partial * arrays in the same way <code>new Field[rows][]</code> works) * @return a new array */ @SuppressWarnings("unchecked") protected static <T extends FieldElement<T>> T[][] buildArray(final Field<T> field, final int rows, final int columns) { if (columns < 0) { T[] dummyRow = (T[]) Array.newInstance(field.getZero().getClass(), 0); return (T[][]) Array.newInstance(dummyRow.getClass(), rows); } T[][] array = (T[][]) Array.newInstance(field.getZero().getClass(), new int[] { rows, columns }); for (int i = 0; i < array.length; ++i) { Arrays.fill(array[i], field.getZero()); } return array; } /** Build an array of elements. * <p> * Arrays are filled with field.getZero() * </p> * @param <T> the type of the field elements * @param field field to which array elements belong * @param length of the array * @return a new array */ protected static <T extends FieldElement<T>> T[] buildArray(final Field<T> field, final int length) { @SuppressWarnings("unchecked") // OK because field must be correct class T[] array = (T[]) Array.newInstance(field.

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS><T> multiply(final FieldMatrix<T> m) throws IllegalArgumentException { // safety check checkMultiplicationCompatible(m); final int nRows = getRowDimension(); final int nCols = m.getColumnDimension(); final int nSum = getColumnDimension(); final FieldMatrix<T> out = createMatrix(nRows, nCols); for (int row = 0; row < nRows; ++row) { for (int col = 0; col < nCols; ++col) { T sum = field.getZero(); for (int i = 0; i < nSum; ++i) { sum = sum.add(getEntry(row, i).multiply(m.getEntry(i, col))); } out.setEntry(row, col, sum); } } return out; } /** {@inheritDoc} */ public FieldMatrix<T> preMultiply(final FieldMatrix<T> m) throws IllegalArgumentException { return m.multiply(this); } /** {@inheritDoc} */ public T[][] getData() { final T[][] data = buildArray(field, getRowDimension(), getColumnDimension()); for (int i = 0; i < data.length; ++i) { final T[] dataI = data[i]; for (int j = 0; j < dataI.length; ++j) { dataI[j] = getEntry(i, j); } } return data; } /** {@inheritDoc} */ public FieldMatrix<T> getSubMatrix(final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException { checkSubMatrixIndex(startRow, endRow, startColumn, endColumn); final FieldMatrix<T> subMatrix = createMatrix(endRow - startRow + 1, endColumn - startColumn + 1); for (int i = startRow; i <= endRow; ++i) { for (int j = startColumn; j <= endColumn; ++j) { subMatrix.setEntry(i - startRow, j - startColumn, getEntry(i, j)); } } return subMatrix; } /** {@inheritDoc} */ public FieldMatrix<T> getSubMatrix(final int[] selectedRows, final int[] selectedColumns) throws MatrixIndexException { // safety checks checkSubMatrixIndex(selectedRows, selectedColumns); // copy entries final FieldMatrix<T> subMatrix = createMatrix(selectedRows.length, selectedColumns.length); subMatrix.walkInOptimizedOrder(new DefaultFieldMatrixChangingVisitor<T>(field.getZero()) { /** {@inheritDoc} */ @Override public T visit(final int row, final int column, final T value) { return getEntry(selectedRows[row], selectedColumns[column]); } }); return subMatrix

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>; } /** {@inheritDoc} */ public void copySubMatrix(final int startRow, final int endRow, final int startColumn, final int endColumn, final T[][] destination) throws MatrixIndexException, IllegalArgumentException { // safety checks checkSubMatrixIndex(startRow, endRow, startColumn, endColumn); final int rowsCount = endRow + 1 - startRow; final int columnsCount = endColumn + 1 - startColumn; if ((destination.length < rowsCount) || (destination[0].length < columnsCount)) { throw MathRuntimeException.createIllegalArgumentException( "dimensions mismatch: got {0}x{1} but expected {2}x{3}", destination.length, destination[0].length, rowsCount, columnsCount); } // copy entries walkInOptimizedOrder(new DefaultFieldMatrixPreservingVisitor<T>(field.getZero()) { /** Initial row index. */ private int startRow; /** Initial column index. */ private int startColumn; /** {@inheritDoc} */ @Override public void start(final int rows, final int columns, final int startRow, final int endRow, final int startColumn, final int endColumn) { this.startRow = startRow; this.startColumn = startColumn; } /** {@inheritDoc} */ @Override public void visit(final int row, final int column, final T value) { destination[row - startRow][column - startColumn] = value; } }, startRow, endRow, startColumn, endColumn); } /** {@inheritDoc} */ public void copySubMatrix(int[] selectedRows, int[] selectedColumns, T[][] destination) throws MatrixIndexException, IllegalArgumentException { // safety checks checkSubMatrixIndex(selectedRows, selectedColumns); if ((destination.length < selectedRows.length) || (destination[0].length < selectedColumns.length)) { throw MathRuntimeException.createIllegalArgumentException( "dimensions mismatch: got {0}x{1} but expected {2}x{3}", destination.length, destination[0].length, selectedRows.length, selectedColumns.length); } // copy entries for (int i = 0; i < selectedRows.length; i++) { final T[] destinationI = destination[i]; for (int j = 0; j < selectedColumns.length; j++) { destinationI[j] = getEntry(selectedRows[i], selectedColumns[j]); } } } /** {@inheritDoc} */ public void setSubMatrix(final T[][] subMatrix, final int row, final int column) throws MatrixIndexException { final int nRows = subMatrix.length; if (nRows == 0) { throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row"); } final int nCols = subMatrix[0].length;

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> if (nCols == 0) { throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column"); } for (int r = 1; r < nRows; ++r) { if (subMatrix[r].length != nCols) { throw MathRuntimeException.createIllegalArgumentException( "some rows have length {0} while others have length {1}", nCols, subMatrix[r].length); } } checkRowIndex(row); checkColumnIndex(column); checkRowIndex(nRows + row - 1); checkColumnIndex(nCols + column - 1); for (int i = 0; i < nRows; ++i) { for (int j = 0; j < nCols; ++j) { setEntry(row + i, column + j, subMatrix[i][j]); } } } /** {@inheritDoc} */ public FieldMatrix<T> getRowMatrix(final int row) throws MatrixIndexException { checkRowIndex(row); final int nCols = getColumnDimension(); final FieldMatrix<T> out = createMatrix(1, nCols); for (int i = 0; i < nCols; ++i) { out.setEntry(0, i, getEntry(row, i)); } return out; } /** {@inheritDoc} */ public void setRowMatrix(final int row, final FieldMatrix<T> matrix) throws MatrixIndexException, InvalidMatrixException { checkRowIndex(row); final int nCols = getColumnDimension(); if ((matrix.getRowDimension() != 1) || (matrix.getColumnDimension() != nCols)) { throw new InvalidMatrixException( "dimensions mismatch: got {0}x{1} but expected {2}x{3}", matrix.getRowDimension(), matrix.getColumnDimension(), 1, nCols); } for (int i = 0; i < nCols; ++i) { setEntry(row, i, matrix.getEntry(0, i)); } } /** {@inheritDoc} */ public FieldMatrix<T> getColumnMatrix(final int column) throws MatrixIndexException { checkColumnIndex(column); final int nRows = getRowDimension(); final FieldMatrix<T> out = createMatrix(nRows, 1); for (int i = 0; i < nRows; ++i) { out.setEntry(i, 0, getEntry(i, column)); } return out; } /** {@inheritDoc} */ public void setColumnMatrix(final int column, final FieldMatrix<T> matrix) throws MatrixIndexException, InvalidMatrixException { checkColumnIndex(column); final int nRows = getRowDimension(); if ((matrix.getRowDimension() != nRows) || (matrix.getColumnDimension() != 1)) { throw new InvalidMatrixException

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>( "dimensions mismatch: got {0}x{1} but expected {2}x{3}", matrix.getRowDimension(), matrix.getColumnDimension(), nRows, 1); } for (int i = 0; i < nRows; ++i) { setEntry(i, column, matrix.getEntry(i, 0)); } } /** {@inheritDoc} */ public FieldVector<T> getRowVector(final int row) throws MatrixIndexException { return new ArrayFieldVector<T>(getRow(row), false); } /** {@inheritDoc} */ public void setRowVector(final int row, final FieldVector<T> vector) throws MatrixIndexException, InvalidMatrixException { checkRowIndex(row); final int nCols = getColumnDimension(); if (vector.getDimension() != nCols) { throw new InvalidMatrixException( "dimensions mismatch: got {0}x{1} but expected {2}x{3}", 1, vector.getDimension(), 1, nCols); } for (int i = 0; i < nCols; ++i) { setEntry(row, i, vector.getEntry(i)); } } /** {@inheritDoc} */ public FieldVector<T> getColumnVector(final int column) throws MatrixIndexException { return new ArrayFieldVector<T>(getColumn(column), false); } /** {@inheritDoc} */ public void setColumnVector(final int column, final FieldVector<T> vector) throws MatrixIndexException, InvalidMatrixException { checkColumnIndex(column); final int nRows = getRowDimension(); if (vector.getDimension() != nRows) { throw new InvalidMatrixException( "dimensions mismatch: got {0}x{1} but expected {2}x{3}", vector.getDimension(), 1, nRows, 1); } for (int i = 0; i < nRows; ++i) { setEntry(i, column, vector.getEntry(i)); } } /** {@inheritDoc} */ public T[] getRow(final int row) throws MatrixIndexException { checkRowIndex(row); final int nCols = getColumnDimension(); final T[] out = buildArray(field, nCols); for (int i = 0; i < nCols; ++i) { out[i] = getEntry(row, i); } return out; } /** {@inheritDoc} */ public void setRow(final int row, final T[] array) throws MatrixIndexException, InvalidMatrixException { checkRowIndex(row); final int nCols = getColumnDimension(); if (array.length != nCols) { throw new InvalidMatrixException( "dimensions mismatch: got {0}x{1} but expected {2}x{3}", 1, array.length, 1, nCols

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>); } for (int i = 0; i < nCols; ++i) { setEntry(row, i, array[i]); } } /** {@inheritDoc} */ public T[] getColumn(final int column) throws MatrixIndexException { checkColumnIndex(column); final int nRows = getRowDimension(); final T[] out = buildArray(field, nRows); for (int i = 0; i < nRows; ++i) { out[i] = getEntry(i, column); } return out; } /** {@inheritDoc} */ public void setColumn(final int column, final T[] array) throws MatrixIndexException, InvalidMatrixException { checkColumnIndex(column); final int nRows = getRowDimension(); if (array.length != nRows) { throw new InvalidMatrixException( "dimensions mismatch: got {0}x{1} but expected {2}x{3}", array.length, 1, nRows, 1); } for (int i = 0; i < nRows; ++i) { setEntry(i, column, array[i]); } } /** {@inheritDoc} */ public abstract T getEntry(int row, int column) throws MatrixIndexException; /** {@inheritDoc} */ public abstract void setEntry(int row, int column, T value) throws MatrixIndexException; /** {@inheritDoc} */ public abstract void addToEntry(int row, int column, T increment) throws MatrixIndexException; /** {@inheritDoc} */ public abstract void multiplyEntry(int row, int column, T factor) throws MatrixIndexException; /** {@inheritDoc} */ public FieldMatrix<T> transpose() { final int nRows = getRowDimension(); final int nCols = getColumnDimension(); final FieldMatrix<T> out = createMatrix(nCols, nRows); walkInOptimizedOrder(new DefaultFieldMatrixPreservingVisitor<T>(field.getZero()) { /** {@inheritDoc} */ @Override public void visit(final int row, final int column, final T value) { out.setEntry(column, row, value); } }); return out; } /** {@inheritDoc} */ public boolean isSquare() { return getColumnDimension() == getRowDimension(); } /** {@inheritDoc} */ public abstract int getRowDimension(); /** {@inheritDoc} */ public abstract int getColumnDimension(); /** {@inheritDoc} */ public T getTrace() throws NonSquareMatrixException { final int nRows = getRowDimension(); final int nCols = getColumnDimension(); if (nRows != nCols) { throw new NonSquareMatrixException(nRows, nCols); } T trace = field.getZero(); for (int i = 0; i < nRows; ++i) { trace =

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> trace.add(getEntry(i, i)); } return trace; } /** {@inheritDoc} */ public T[] operate(final T[] v) throws IllegalArgumentException { final int nRows = getRowDimension(); final int nCols = getColumnDimension(); if (v.length != nCols) { throw MathRuntimeException.createIllegalArgumentException( "vector length mismatch: got {0} but expected {1}", v.length, nCols); } final T[] out = buildArray(field, nRows); for (int row = 0; row < nRows; ++row) { T sum = field.getZero(); for (int i = 0; i < nCols; ++i) { sum = sum.add(getEntry(row, i).multiply(v[i])); } out[row] = sum; } return out; } /** {@inheritDoc} */ public FieldVector<T> operate(final FieldVector<T> v) throws IllegalArgumentException { try { return new ArrayFieldVector<T>(operate(((ArrayFieldVector<T>) v).getDataRef()), false); } catch (ClassCastException cce) { final int nRows = getRowDimension(); final int nCols = getColumnDimension(); if (v.getDimension() != nCols) { throw MathRuntimeException.createIllegalArgumentException( "vector length mismatch: got {0} but expected {1}", v.getDimension(), nCols); } final T[] out = buildArray(field, nRows); for (int row = 0; row < nRows; ++row) { T sum = field.getZero(); for (int i = 0; i < nCols; ++i) { sum = sum.add(getEntry(row, i).multiply(v.getEntry(i))); } out[row] = sum; } return new ArrayFieldVector<T>(out, false); } } /** {@inheritDoc} */ public T[] preMultiply(final T[] v) throws IllegalArgumentException { final int nRows = getRowDimension(); final int nCols = getColumnDimension(); if (v.length != nRows) { throw MathRuntimeException.createIllegalArgumentException( "vector length mismatch: got {0} but expected {1}", v.length, nRows); } final T[] out = buildArray(field, nCols); for (int col = 0; col < nCols; ++col) { T sum = field.getZero(); for (int i = 0; i < nRows; ++i) { sum = sum.add(getEntry(i, col).multiply(v[i])); } out[col] = sum; } return out; } /** {@inheritDoc} */ public FieldVector<T> preMultiply(final FieldVector<T> v) throws IllegalArgumentException { try {

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> return new ArrayFieldVector<T>(preMultiply(((ArrayFieldVector<T>) v).getDataRef()), false); } catch (ClassCastException cce) { final int nRows = getRowDimension(); final int nCols = getColumnDimension(); if (v.getDimension() != nRows) { throw MathRuntimeException.createIllegalArgumentException( "vector length mismatch: got {0} but expected {1}", v.getDimension(), nRows); } final T[] out = buildArray(field, nCols); for (int col = 0; col < nCols; ++col) { T sum = field.getZero(); for (int i = 0; i < nRows; ++i) { sum = sum.add(getEntry(i, col).multiply(v.getEntry(i))); } out[col] = sum; } return new ArrayFieldVector<T>(out); } } /** {@inheritDoc} */ public T walkInRowOrder(final FieldMatrixChangingVisitor<T> visitor) throws MatrixVisitorException { final int rows = getRowDimension(); final int columns = getColumnDimension(); visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int row = 0; row < rows; ++row) { for (int column = 0; column < columns; ++column) { final T oldValue = getEntry(row, column); final T newValue = visitor.visit(row, column, oldValue); setEntry(row, column, newValue); } } return visitor.end(); } /** {@inheritDoc} */ public T walkInRowOrder(final FieldMatrixPreservingVisitor<T> visitor) throws MatrixVisitorException { final int rows = getRowDimension(); final int columns = getColumnDimension(); visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int row = 0; row < rows; ++row) { for (int column = 0; column < columns; ++column) { visitor.visit(row, column, getEntry(row, column)); } } return visitor.end(); } /** {@inheritDoc} */ public T walkInRowOrder(final FieldMatrixChangingVisitor<T> visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException, MatrixVisitorException { checkSubMatrixIndex(startRow, endRow, startColumn, endColumn); visitor.start(getRowDimension(), getColumnDimension(), startRow, endRow, startColumn, endColumn); for (int row = startRow; row <= endRow; ++row) { for (int column = startColumn; column <= endColumn; ++column) { final T oldValue = getEntry(row, column); final

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>, oldValue); setEntry(row, column, newValue); } } return visitor.end(); } /** {@inheritDoc} */ public T walkInColumnOrder(final FieldMatrixPreservingVisitor<T> visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException, MatrixVisitorException { checkSubMatrixIndex(startRow, endRow, startColumn, endColumn); visitor.start(getRowDimension(), getColumnDimension(), startRow, endRow, startColumn, endColumn); for (int column = startColumn; column <= endColumn; ++column) { for (int row = startRow; row <= endRow; ++row) { visitor.visit(row, column, getEntry(row, column)); } } return visitor.end(); } /** {@inheritDoc} */ public T walkInOptimizedOrder(final FieldMatrixChangingVisitor<T> visitor) throws MatrixVisitorException { return walkInRowOrder(visitor); } /** {@inheritDoc} */ public T walkInOptimizedOrder(final FieldMatrixPreservingVisitor<T> visitor) throws MatrixVisitorException { return walkInRowOrder(visitor); } /** {@inheritDoc} */ public T walkInOptimizedOrder(final FieldMatrixChangingVisitor<T> visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException, MatrixVisitorException { return walkInRowOrder(visitor, startRow, endRow, startColumn, endColumn); } /** {@inheritDoc} */ public T walkInOptimizedOrder(final FieldMatrixPreservingVisitor<T> visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException, MatrixVisitorException { return walkInRowOrder(visitor, startRow, endRow, startColumn, endColumn); } /** * Get a string representation for this matrix. * @return a string representation for this matrix */ @Override public String toString() { final int nRows = getRowDimension(); final int nCols = getColumnDimension(); final StringBuffer res = new StringBuffer(); String fullClassName = getClass().getName(); String shortClassName = fullClassName.substring(fullClassName.lastIndexOf('.') + 1); res.append(shortClassName).append("{"); for (int i = 0; i < nRows; ++i) { if (i > 0) { res.append(","); } res.append("{"); for (int j = 0; j < nCols; ++j) { if (j > 0) { res.append(","); } res.append(getEntry(i, j)); } res.append("}"); } res.append("}"); return res.toString(); } /** * Returns true iff <

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.math.ode; /** * This class is used in the junit tests for the ODE integrators. * <p>This specific problem is the following differential equation : * <pre> * y' = -y * </pre> * the solution of this equation is a simple exponential function : * <pre> * y (t) = y (t0) exp (t0-t) * </pre> * </p> */ public class TestProblem1 extends TestProblemAbstract { /** Serializable version identifier. */ private static final long serialVersionUID = 1977870815289373164L; /** theoretical state */ private double[] y; /** * Simple constructor. */ public TestProblem1() { super(); double[] y0 = { 1.0, 0.1 }; setInitialConditions(0.0, y0); setFinalConditions(4.0); double[] errorScale = { 1.0, 1.0 }; setErrorScale(errorScale); y = new double[y0.length]; } /** * Copy constructor. * @param problem problem to copy */ public TestProblem1(TestProblem1 problem) { super(problem); y = problem.y.clone(); } /** {@inheritDoc} */ @Override public TestProblem1 copy() { return new TestProblem1(this); } @Override public void doComputeDerivatives(double t, double[] y, double[] yDot) { // compute the derivatives for (int i = 0; i < n; ++i) yDot[i] = -y[i]; } @Override public double[] computeTheoreticalState(double t) { double c = Math.exp (t0 - t); for (int i = 0; i < n; ++i) { y[i] = c * y0[i]; } return y; } }

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>row]; final double[] outDataRow = outData[row]; for (int col = 0; col < nCols; col++) { double sum = 0; for (int i = 0; i < nSum; i++) { sum += dataRow[i] * m.data[i][col]; } outDataRow[col] = sum; } } return new Array2DRowRealMatrix(outData, false); } /** {@inheritDoc} */ @Override public double[][] getData() { return copyOut(); } /** * Returns a reference to the underlying data array. * <p> * Does <strong>not</strong> make a fresh copy of the underlying data.</p> * * @return 2-dimensional array of entries */ public double[][] getDataRef() { return data; } /** {@inheritDoc} */ @Override public void setSubMatrix(final double[][] subMatrix, final int row, final int column) throws MatrixIndexException { if (data == null) { if (row > 0) { throw MathRuntimeException.createIllegalStateException( "first {0} rows are not initialized yet", row); } if (column > 0) { throw MathRuntimeException.createIllegalStateException( "first {0} columns are not initialized yet", column); } final int nRows = subMatrix.length; if (nRows == 0) { throw MathRuntimeException.createIllegalArgumentException( AT_LEAST_ONE_ROW_MESSAGE); } final int nCols = subMatrix[0].length; if (nCols == 0) { throw MathRuntimeException.createIllegalArgumentException( AT_LEAST_ONE_COLUMN_MESSAGE); } data = new double[subMatrix.length][nCols]; for (int i = 0; i < data.length; ++i) { if (subMatrix[i].length != nCols) { throw MathRuntimeException.createIllegalArgumentException( DIFFERENT_ROWS_LENGTHS_MESSAGE, nCols, subMatrix[i].length); } System.arraycopy(subMatrix[i], 0, data[i + row], column, nCols); } } else { super.setSubMatrix(subMatrix, row, column); } } /** {@inheritDoc} */ @Override public double getEntry(final int row, final int column) throws MatrixIndexException { try { return data[row][column]; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( NO_ENTRY_MESSAGE, row, column, getRowDimension(), getColumnDimension()); } } /** {@inheritDoc} */ @Override public void setEntry(final int row, final int column, final double value) throws MatrixIndexException { try { data[row][column] = value; } catch (ArrayIndexOutOfBoundsException e

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>) { throw new MatrixIndexException( NO_ENTRY_MESSAGE, row, column, getRowDimension(), getColumnDimension()); } } /** {@inheritDoc} */ @Override public void addToEntry(final int row, final int column, final double increment) throws MatrixIndexException { try { data[row][column] += increment; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( NO_ENTRY_MESSAGE, row, column, getRowDimension(), getColumnDimension()); } } /** {@inheritDoc} */ @Override public void multiplyEntry(final int row, final int column, final double factor) throws MatrixIndexException { try { data[row][column] *= factor; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( NO_ENTRY_MESSAGE, row, column, getRowDimension(), getColumnDimension()); } } /** {@inheritDoc} */ @Override public int getRowDimension() { return (data == null) ? 0 : data.length; } /** {@inheritDoc} */ @Override public int getColumnDimension() { return ((data == null) || (data[0] == null)) ? 0 : data[0].length; } /** {@inheritDoc} */ @Override public double[] operate(final double[] v) throws IllegalArgumentException { final int nRows = this.getRowDimension(); final int nCols = this.getColumnDimension(); if (v.length != nCols) { throw MathRuntimeException.createIllegalArgumentException( VECTOR_LENGTHS_MISMATCH, v.length, nCols); } final double[] out = new double[nRows]; for (int row = 0; row < nRows; row++) { final double[] dataRow = data[row]; double sum = 0; for (int i = 0; i < nCols; i++) { sum += dataRow[i] * v[i]; } out[row] = sum; } return out; } /** {@inheritDoc} */ @Override public double[] preMultiply(final double[] v) throws IllegalArgumentException { final int nRows = getRowDimension(); final int nCols = getColumnDimension(); if (v.length != nRows) { throw MathRuntimeException.createIllegalArgumentException( VECTOR_LENGTHS_MISMATCH, v.length, nRows); } final double[] out = new double[nCols]; for (int col = 0; col < nCols; ++col) { double sum = 0; for (int i = 0; i < nRows; ++i) { sum += data[i][col] * v[i]; } out[col] = sum; } return out; } /** {@inheritDoc} */ @Override public double walkInRowOrder(final RealMatrix

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>ChangingVisitor visitor) throws MatrixVisitorException { final int rows = getRowDimension(); final int columns = getColumnDimension(); visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int i = 0; i < rows; ++i) { final double[] rowI = data[i]; for (int j = 0; j < columns; ++j) { rowI[j] = visitor.visit(i, j, rowI[j]); } } return visitor.end(); } /** {@inheritDoc} */ @Override public double walkInRowOrder(final RealMatrixPreservingVisitor visitor) throws MatrixVisitorException { final int rows = getRowDimension(); final int columns = getColumnDimension(); visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int i = 0; i < rows; ++i) { final double[] rowI = data[i]; for (int j = 0; j < columns; ++j) { visitor.visit(i, j, rowI[j]); } } return visitor.end(); } /** {@inheritDoc} */ @Override public double walkInRowOrder(final RealMatrixChangingVisitor visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException, MatrixVisitorException { MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn); visitor.start(getRowDimension(), getColumnDimension(), startRow, endRow, startColumn, endColumn); for (int i = startRow; i <= endRow; ++i) { final double[] rowI = data[i]; for (int j = startColumn; j <= endColumn; ++j) { rowI[j] = visitor.visit(i, j, rowI[j]); } } return visitor.end(); } /** {@inheritDoc} */ @Override public double walkInRowOrder(final RealMatrixPreservingVisitor visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException, MatrixVisitorException { MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn); visitor.start(getRowDimension(), getColumnDimension(), startRow, endRow, startColumn, endColumn); for (int i = startRow; i <= endRow; ++i) { final double[] rowI = data[i]; for (int j = startColumn; j <= endColumn; ++j) { visitor.visit(i, j, rowI[j]); } } return visitor.end(); } /** {@inheritDoc} */ @Override public double walkIn

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>ColumnOrder(final RealMatrixChangingVisitor visitor) throws MatrixVisitorException { final int rows = getRowDimension(); final int columns = getColumnDimension(); visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int j = 0; j < columns; ++j) { for (int i = 0; i < rows; ++i) { final double[] rowI = data[i]; rowI[j] = visitor.visit(i, j, rowI[j]); } } return visitor.end(); } /** {@inheritDoc} */ @Override public double walkInColumnOrder(final RealMatrixPreservingVisitor visitor) throws MatrixVisitorException { final int rows = getRowDimension(); final int columns = getColumnDimension(); visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int j = 0; j < columns; ++j) { for (int i = 0; i < rows; ++i) { visitor.visit(i, j, data[i][j]); } } return visitor.end(); } /** {@inheritDoc} */ @Override public double walkInColumnOrder(final RealMatrixChangingVisitor visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException, MatrixVisitorException { MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn); visitor.start(getRowDimension(), getColumnDimension(), startRow, endRow, startColumn, endColumn); for (int j = startColumn; j <= endColumn; ++j) { for (int i = startRow; i <= endRow; ++i) { final double[] rowI = data[i]; rowI[j] = visitor.visit(i, j, rowI[j]); } } return visitor.end(); } /** {@inheritDoc} */ @Override public double walkInColumnOrder(final RealMatrixPreservingVisitor visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException, MatrixVisitorException { MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn); visitor.start(getRowDimension(), getColumnDimension(), startRow, endRow, startColumn, endColumn); for (int j = startColumn; j <= endColumn; ++j) { for (int i = startRow; i <= endRow; ++i) { visitor.visit(i, j, data[i][j]); } } return visitor.end(); } /** * Returns a fresh copy of the underlying data array. * * @return a copy of the underlying data array.

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> */ private double[][] copyOut() { final int nRows = this.getRowDimension(); final double[][] out = new double[nRows][this.getColumnDimension()]; // can't copy 2-d array in one shot, otherwise get row references for (int i = 0; i < nRows; i++) { System.arraycopy(data[i], 0, out[i], 0, data[i].length); } return out; } /** * Replaces data with a fresh copy of the input array. * <p> * Verifies that the input array is rectangular and non-empty.</p> * * @param in data to copy in * @throws IllegalArgumentException if input array is empty or not * rectangular * @throws NullPointerException if input array is null */ private void copyIn(final double[][] in) { setSubMatrix(in, 0, 0); } }

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> matrix * is split in square blocks (except at right and bottom side where blocks may * be rectangular to fit matrix size) and each block is stored in a flattened * one-dimensional array. * </p> * <p> * This method creates an array in blocks layout from an input array in raw layout. * It can be used to provide the array argument of the {@link * #BlockFieldMatrix(int, int, FieldElement[][], boolean)} * constructor. * </p> * @param <T> the type of the field elements * @param rawData data array in raw layout * @return a new data array containing the same entries but in blocks layout * @exception IllegalArgumentException if <code>rawData</code> is not rectangular * (not all rows have the same length) * @see #createBlocksLayout(Field, int, int) * @see #BlockFieldMatrix(int, int, FieldElement[][], boolean) */ public static <T extends FieldElement<T>> T[][] toBlocksLayout(final T[][] rawData) throws IllegalArgumentException { final int rows = rawData.length; final int columns = rawData[0].length; final int blockRows = (rows + BLOCK_SIZE - 1) / BLOCK_SIZE; final int blockColumns = (columns + BLOCK_SIZE - 1) / BLOCK_SIZE; // safety checks for (int i = 0; i < rawData.length; ++i) { final int length = rawData[i].length; if (length != columns) { throw MathRuntimeException.createIllegalArgumentException( "some rows have length {0} while others have length {1}", columns, length); } } // convert array final Field<T> field = extractField(rawData); final T[][] blocks = buildArray(field, blockRows * blockColumns, -1); int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); final int iHeight = pEnd - pStart; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; final int qEnd = Math.min(qStart + BLOCK_SIZE, columns); final int jWidth = qEnd - qStart; // allocate new block final T[] block = buildArray(field, iHeight * jWidth); blocks[blockIndex] = block; // copy data int index = 0; for (int p = pStart; p < pEnd; ++p) { System.arraycopy(rawData[p], qStart, block, index, jWidth); index

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> += jWidth; } ++blockIndex; } } return blocks; } /** * Create a data array in blocks layout. * <p> * This method can be used to create the array argument of the {@link * #BlockFieldMatrix(int, int, FieldElement[][], boolean)} * constructor. * </p> * @param <T> the type of the field elements * @param field field to which the elements belong * @param rows the number of rows in the new matrix * @param columns the number of columns in the new matrix * @return a new data array in blocks layout * @see #toBlocksLayout(FieldElement[][]) * @see #BlockFieldMatrix(int, int, FieldElement[][], boolean) */ public static <T extends FieldElement<T>> T[][] createBlocksLayout(final Field<T> field, final int rows, final int columns) { final int blockRows = (rows + BLOCK_SIZE - 1) / BLOCK_SIZE; final int blockColumns = (columns + BLOCK_SIZE - 1) / BLOCK_SIZE; final T[][] blocks = buildArray(field, blockRows * blockColumns, -1); int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); final int iHeight = pEnd - pStart; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; final int qEnd = Math.min(qStart + BLOCK_SIZE, columns); final int jWidth = qEnd - qStart; blocks[blockIndex] = buildArray(field, iHeight * jWidth); ++blockIndex; } } return blocks; } /** {@inheritDoc} */ @Override public FieldMatrix<T> createMatrix(final int rowDimension, final int columnDimension) throws IllegalArgumentException { return new BlockFieldMatrix<T>(getField(), rowDimension, columnDimension); } /** {@inheritDoc} */ @Override public FieldMatrix<T> copy() { // create an empty matrix BlockFieldMatrix<T> copied = new BlockFieldMatrix<T>(getField(), rows, columns); // copy the blocks for (int i = 0; i < blocks.length; ++i) { System.arraycopy(blocks[i], 0, copied.blocks[i], 0, blocks[i].length); } return copied; } /** {@inheritDoc} */ @Override public FieldMatrix<T> add(final FieldMatrix<T> m) throws IllegalArgumentException { try { return add((BlockFieldMatrix<T>) m

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>); } catch (ClassCastException cce) { // safety check checkAdditionCompatible(m); final BlockFieldMatrix<T> out = new BlockFieldMatrix<T>(getField(), rows, columns); // perform addition block-wise, to ensure good cache behavior int blockIndex = 0; for (int iBlock = 0; iBlock < out.blockRows; ++iBlock) { for (int jBlock = 0; jBlock < out.blockColumns; ++jBlock) { // perform addition on the current block final T[] outBlock = out.blocks[blockIndex]; final T[] tBlock = blocks[blockIndex]; final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); final int qStart = jBlock * BLOCK_SIZE; final int qEnd = Math.min(qStart + BLOCK_SIZE, columns); int k = 0; for (int p = pStart; p < pEnd; ++p) { for (int q = qStart; q < qEnd; ++q) { outBlock[k] = tBlock[k].add(m.getEntry(p, q)); ++k; } } // go to next block ++blockIndex; } } return out; } } /** * Compute the sum of this and <code>m</code>. * * @param m matrix to be added * @return this + m * @throws IllegalArgumentException if m is not the same size as this */ public BlockFieldMatrix<T> add(final BlockFieldMatrix<T> m) throws IllegalArgumentException { // safety check checkAdditionCompatible(m); final BlockFieldMatrix<T> out = new BlockFieldMatrix<T>(getField(), rows, columns); // perform addition block-wise, to ensure good cache behavior for (int blockIndex = 0; blockIndex < out.blocks.length; ++blockIndex) { final T[] outBlock = out.blocks[blockIndex]; final T[] tBlock = blocks[blockIndex]; final T[] mBlock = m.blocks[blockIndex]; for (int k = 0; k < outBlock.length; ++k) { outBlock[k] = tBlock[k].add(mBlock[k]); } } return out; } /** {@inheritDoc} */ @Override public FieldMatrix<T> subtract(final FieldMatrix<T> m) throws IllegalArgumentException { try { return subtract((BlockFieldMatrix<T>) m); } catch (ClassCastException cce) { // safety check checkSubtractionCompatible(m); final BlockFieldMatrix<T> out = new BlockFieldMatrix<T>(getField(), rows, columns); // perform subtraction block-wise

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>, to ensure good cache behavior int blockIndex = 0; for (int iBlock = 0; iBlock < out.blockRows; ++iBlock) { for (int jBlock = 0; jBlock < out.blockColumns; ++jBlock) { // perform subtraction on the current block final T[] outBlock = out.blocks[blockIndex]; final T[] tBlock = blocks[blockIndex]; final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); final int qStart = jBlock * BLOCK_SIZE; final int qEnd = Math.min(qStart + BLOCK_SIZE, columns); int k = 0; for (int p = pStart; p < pEnd; ++p) { for (int q = qStart; q < qEnd; ++q) { outBlock[k] = tBlock[k].subtract(m.getEntry(p, q)); ++k; } } // go to next block ++blockIndex; } } return out; } } /** * Compute this minus <code>m</code>. * * @param m matrix to be subtracted * @return this - m * @throws IllegalArgumentException if m is not the same size as this */ public BlockFieldMatrix<T> subtract(final BlockFieldMatrix<T> m) throws IllegalArgumentException { // safety check checkSubtractionCompatible(m); final BlockFieldMatrix<T> out = new BlockFieldMatrix<T>(getField(), rows, columns); // perform subtraction block-wise, to ensure good cache behavior for (int blockIndex = 0; blockIndex < out.blocks.length; ++blockIndex) { final T[] outBlock = out.blocks[blockIndex]; final T[] tBlock = blocks[blockIndex]; final T[] mBlock = m.blocks[blockIndex]; for (int k = 0; k < outBlock.length; ++k) { outBlock[k] = tBlock[k].subtract(mBlock[k]); } } return out; } /** {@inheritDoc} */ @Override public FieldMatrix<T> scalarAdd(final T d) throws IllegalArgumentException { final BlockFieldMatrix<T> out = new BlockFieldMatrix<T>(getField(), rows, columns); // perform subtraction block-wise, to ensure good cache behavior for (int blockIndex = 0; blockIndex < out.blocks.length; ++blockIndex) { final T[] outBlock = out.blocks[blockIndex]; final T[] tBlock = blocks[blockIndex]; for (int k = 0; k < outBlock.length; ++k) { outBlock[k] = tBlock[k].add(

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>d); } } return out; } /** {@inheritDoc} */ @Override public FieldMatrix<T> scalarMultiply(final T d) throws IllegalArgumentException { final BlockFieldMatrix<T> out = new BlockFieldMatrix<T>(getField(), rows, columns); // perform subtraction block-wise, to ensure good cache behavior for (int blockIndex = 0; blockIndex < out.blocks.length; ++blockIndex) { final T[] outBlock = out.blocks[blockIndex]; final T[] tBlock = blocks[blockIndex]; for (int k = 0; k < outBlock.length; ++k) { outBlock[k] = tBlock[k].multiply(d); } } return out; } /** {@inheritDoc} */ @Override public FieldMatrix<T> multiply(final FieldMatrix<T> m) throws IllegalArgumentException { try { return multiply((BlockFieldMatrix<T>) m); } catch (ClassCastException cce) { // safety check checkMultiplicationCompatible(m); final BlockFieldMatrix<T> out = new BlockFieldMatrix<T>(getField(), rows, m.getColumnDimension()); final T zero = getField().getZero(); // perform multiplication block-wise, to ensure good cache behavior int blockIndex = 0; for (int iBlock = 0; iBlock < out.blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < out.blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; final int qEnd = Math.min(qStart + BLOCK_SIZE, m.getColumnDimension()); // select current block final T[] outBlock = out.blocks[blockIndex]; // perform multiplication on current block for (int kBlock = 0; kBlock < blockColumns; ++kBlock) { final int kWidth = blockWidth(kBlock); final T[] tBlock = blocks[iBlock * blockColumns + kBlock]; final int rStart = kBlock * BLOCK_SIZE; int k = 0; for (int p = pStart; p < pEnd; ++p) { final int lStart = (p - pStart) * kWidth; final int lEnd = lStart + kWidth; for (int q = qStart; q < qEnd; ++q) { T sum = zero; int r = rStart; for (int l = lStart; l < lEnd; ++l) { sum = sum.add(tBlock[l].multiply(m.getEntry(r, q))); ++r; } outBlock[k] = outBlock[k].add(sum);

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> ++k; } } } // go to next block ++blockIndex; } } return out; } } /** * Returns the result of postmultiplying this by m. * * @param m matrix to postmultiply by * @return this * m * @throws IllegalArgumentException * if columnDimension(this) != rowDimension(m) */ public BlockFieldMatrix<T> multiply(BlockFieldMatrix<T> m) throws IllegalArgumentException { // safety check checkMultiplicationCompatible(m); final BlockFieldMatrix<T> out = new BlockFieldMatrix<T>(getField(), rows, m.columns); final T zero = getField().getZero(); // perform multiplication block-wise, to ensure good cache behavior int blockIndex = 0; for (int iBlock = 0; iBlock < out.blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < out.blockColumns; ++jBlock) { final int jWidth = out.blockWidth(jBlock); final int jWidth2 = jWidth + jWidth; final int jWidth3 = jWidth2 + jWidth; final int jWidth4 = jWidth3 + jWidth; // select current block final T[] outBlock = out.blocks[blockIndex]; // perform multiplication on current block for (int kBlock = 0; kBlock < blockColumns; ++kBlock) { final int kWidth = blockWidth(kBlock); final T[] tBlock = blocks[iBlock * blockColumns + kBlock]; final T[] mBlock = m.blocks[kBlock * m.blockColumns + jBlock]; int k = 0; for (int p = pStart; p < pEnd; ++p) { final int lStart = (p - pStart) * kWidth; final int lEnd = lStart + kWidth; for (int nStart = 0; nStart < jWidth; ++nStart) { T sum = zero; int l = lStart; int n = nStart; while (l < lEnd - 3) { sum = sum. add(tBlock[l].multiply(mBlock[n])). add(tBlock[l + 1].multiply(mBlock[n + jWidth])). add(tBlock[l + 2].multiply(mBlock[n + jWidth2])). add(tBlock[l + 3].multiply(mBlock[n + jWidth3])); l += 4; n += jWidth4; } while (l < lEnd) { sum = sum.add(tBlock[l++].multiply(mBlock[n]));

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> n += jWidth; } outBlock[k] = outBlock[k].add(sum); ++k; } } } // go to next block ++blockIndex; } } return out; } /** {@inheritDoc} */ @Override public T[][] getData() { final T[][] data = buildArray(getField(), getRowDimension(), getColumnDimension()); final int lastColumns = columns - (blockColumns - 1) * BLOCK_SIZE; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); int regularPos = 0; int lastPos = 0; for (int p = pStart; p < pEnd; ++p) { final T[] dataP = data[p]; int blockIndex = iBlock * blockColumns; int dataPos = 0; for (int jBlock = 0; jBlock < blockColumns - 1; ++jBlock) { System.arraycopy(blocks[blockIndex++], regularPos, dataP, dataPos, BLOCK_SIZE); dataPos += BLOCK_SIZE; } System.arraycopy(blocks[blockIndex], lastPos, dataP, dataPos, lastColumns); regularPos += BLOCK_SIZE; lastPos += lastColumns; } } return data; } /** {@inheritDoc} */ @Override public FieldMatrix<T> getSubMatrix(final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException { // safety checks checkSubMatrixIndex(startRow, endRow, startColumn, endColumn); // create the output matrix final BlockFieldMatrix<T> out = new BlockFieldMatrix<T>(getField(), endRow - startRow + 1, endColumn - startColumn + 1); // compute blocks shifts final int blockStartRow = startRow / BLOCK_SIZE; final int rowsShift = startRow % BLOCK_SIZE; final int blockStartColumn = startColumn / BLOCK_SIZE; final int columnsShift = startColumn % BLOCK_SIZE; // perform extraction block-wise, to ensure good cache behavior int pBlock = blockStartRow; for (int iBlock = 0; iBlock < out.blockRows; ++iBlock) { final int iHeight = out.blockHeight(iBlock); int qBlock = blockStartColumn; for (int jBlock = 0; jBlock < out.blockColumns; ++jBlock) { final int jWidth = out.blockWidth(jBlock); // handle one block of the output matrix final int outIndex = iBlock * out.blockColumns + jBlock; final T[] out

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>-wise, to ensure good cache behavior for (int iBlock = blockStartRow; iBlock < blockEndRow; ++iBlock) { final int iHeight = blockHeight(iBlock); final int firstRow = iBlock * BLOCK_SIZE; final int iStart = Math.max(row, firstRow); final int iEnd = Math.min(endRow + 1, firstRow + iHeight); for (int jBlock = blockStartColumn; jBlock < blockEndColumn; ++jBlock) { final int jWidth = blockWidth(jBlock); final int firstColumn = jBlock * BLOCK_SIZE; final int jStart = Math.max(column, firstColumn); final int jEnd = Math.min(endColumn + 1, firstColumn + jWidth); final int jLength = jEnd - jStart; // handle one block, row by row final T[] block = blocks[iBlock * blockColumns + jBlock]; for (int i = iStart; i < iEnd; ++i) { System.arraycopy(subMatrix[i - row], jStart - column, block, (i - firstRow) * jWidth + (jStart - firstColumn), jLength); } } } } /** {@inheritDoc} */ @Override public FieldMatrix<T> getRowMatrix(final int row) throws MatrixIndexException { checkRowIndex(row); final BlockFieldMatrix<T> out = new BlockFieldMatrix<T>(getField(), 1, columns); // perform copy block-wise, to ensure good cache behavior final int iBlock = row / BLOCK_SIZE; final int iRow = row - iBlock * BLOCK_SIZE; int outBlockIndex = 0; int outIndex = 0; T[] outBlock = out.blocks[outBlockIndex]; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int jWidth = blockWidth(jBlock); final T[] block = blocks[iBlock * blockColumns + jBlock]; final int available = outBlock.length - outIndex; if (jWidth > available) { System.arraycopy(block, iRow * jWidth, outBlock, outIndex, available); outBlock = out.blocks[++outBlockIndex]; System.arraycopy(block, iRow * jWidth, outBlock, 0, jWidth - available); outIndex = jWidth - available; } else { System.arraycopy(block, iRow * jWidth, outBlock, outIndex, jWidth); outIndex += jWidth; } } return out; } /** {@inheritDoc} */ @Override public void setRowMatrix(final int row, final FieldMatrix<T> matrix) throws MatrixIndexException, InvalidMatrixException { try { set

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>Block = out.blocks[outBlockIndex]; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int iHeight = blockHeight(iBlock); final T[] block = blocks[iBlock * blockColumns + jBlock]; for (int i = 0; i < iHeight; ++i) { if (outIndex >= outBlock.length) { outBlock = out.blocks[++outBlockIndex]; outIndex = 0; } outBlock[outIndex++] = block[i * jWidth + jColumn]; } } return out; } /** {@inheritDoc} */ @Override public void setColumnMatrix(final int column, final FieldMatrix<T> matrix) throws MatrixIndexException, InvalidMatrixException { try { setColumnMatrix(column, (BlockFieldMatrix<T>) matrix); } catch (ClassCastException cce) { super.setColumnMatrix(column, matrix); } } /** * Sets the entries in column number <code>column</code> * as a column matrix. Column indices start at 0. * * @param column the column to be set * @param matrix column matrix (must have one column and the same number of rows * as the instance) * @throws MatrixIndexException if the specified column index is invalid * @throws InvalidMatrixException if the matrix dimensions do not match one * instance column */ void setColumnMatrix(final int column, final BlockFieldMatrix<T> matrix) throws MatrixIndexException, InvalidMatrixException { checkColumnIndex(column); final int nRows = getRowDimension(); if ((matrix.getRowDimension() != nRows) || (matrix.getColumnDimension() != 1)) { throw new InvalidMatrixException( "dimensions mismatch: got {0}x{1} but expected {2}x{3}", matrix.getRowDimension(), matrix.getColumnDimension(), nRows, 1); } // perform copy block-wise, to ensure good cache behavior final int jBlock = column / BLOCK_SIZE; final int jColumn = column - jBlock * BLOCK_SIZE; final int jWidth = blockWidth(jBlock); int mBlockIndex = 0; int mIndex = 0; T[] mBlock = matrix.blocks[mBlockIndex]; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int iHeight = blockHeight(iBlock); final T[] block = blocks[iBlock * blockColumns + jBlock]; for (int i = 0; i < iHeight; ++i) { if (mIndex >= mBlock.length) { mBlock = matrix.blocks[++mBlockIndex]; mIndex = 0; } block[i * jWidth + jColumn] = mBlock[mIndex++]; }

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> } } /** {@inheritDoc} */ @Override public FieldVector<T> getRowVector(final int row) throws MatrixIndexException { checkRowIndex(row); final T[] outData = buildArray(getField(), columns); // perform copy block-wise, to ensure good cache behavior final int iBlock = row / BLOCK_SIZE; final int iRow = row - iBlock * BLOCK_SIZE; int outIndex = 0; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int jWidth = blockWidth(jBlock); final T[] block = blocks[iBlock * blockColumns + jBlock]; System.arraycopy(block, iRow * jWidth, outData, outIndex, jWidth); outIndex += jWidth; } return new ArrayFieldVector<T>(outData, false); } /** {@inheritDoc} */ @Override public void setRowVector(final int row, final FieldVector<T> vector) throws MatrixIndexException, InvalidMatrixException { try { setRow(row, ((ArrayFieldVector<T>) vector).getDataRef()); } catch (ClassCastException cce) { super.setRowVector(row, vector); } } /** {@inheritDoc} */ @Override public FieldVector<T> getColumnVector(final int column) throws MatrixIndexException { checkColumnIndex(column); final T[] outData = buildArray(getField(), rows); // perform copy block-wise, to ensure good cache behavior final int jBlock = column / BLOCK_SIZE; final int jColumn = column - jBlock * BLOCK_SIZE; final int jWidth = blockWidth(jBlock); int outIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int iHeight = blockHeight(iBlock); final T[] block = blocks[iBlock * blockColumns + jBlock]; for (int i = 0; i < iHeight; ++i) { outData[outIndex++] = block[i * jWidth + jColumn]; } } return new ArrayFieldVector<T>(outData, false); } /** {@inheritDoc} */ @Override public void setColumnVector(final int column, final FieldVector<T> vector) throws MatrixIndexException, InvalidMatrixException { try { setColumn(column, ((ArrayFieldVector<T>) vector).getDataRef()); } catch (ClassCastException cce) { super.setColumnVector(column, vector); } } /** {@inheritDoc} */ @Override public T[] getRow(final int row) throws MatrixIndexException { checkRowIndex(row); final T[] out = buildArray(getField(), columns); // perform copy block-wise, to ensure good cache behavior final int i

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>Block = row / BLOCK_SIZE; final int iRow = row - iBlock * BLOCK_SIZE; int outIndex = 0; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int jWidth = blockWidth(jBlock); final T[] block = blocks[iBlock * blockColumns + jBlock]; System.arraycopy(block, iRow * jWidth, out, outIndex, jWidth); outIndex += jWidth; } return out; } /** {@inheritDoc} */ @Override public void setRow(final int row, final T[] array) throws MatrixIndexException, InvalidMatrixException { checkRowIndex(row); final int nCols = getColumnDimension(); if (array.length != nCols) { throw new InvalidMatrixException( "dimensions mismatch: got {0}x{1} but expected {2}x{3}", 1, array.length, 1, nCols); } // perform copy block-wise, to ensure good cache behavior final int iBlock = row / BLOCK_SIZE; final int iRow = row - iBlock * BLOCK_SIZE; int outIndex = 0; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int jWidth = blockWidth(jBlock); final T[] block = blocks[iBlock * blockColumns + jBlock]; System.arraycopy(array, outIndex, block, iRow * jWidth, jWidth); outIndex += jWidth; } } /** {@inheritDoc} */ @Override public T[] getColumn(final int column) throws MatrixIndexException { checkColumnIndex(column); final T[] out = buildArray(getField(), rows); // perform copy block-wise, to ensure good cache behavior final int jBlock = column / BLOCK_SIZE; final int jColumn = column - jBlock * BLOCK_SIZE; final int jWidth = blockWidth(jBlock); int outIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int iHeight = blockHeight(iBlock); final T[] block = blocks[iBlock * blockColumns + jBlock]; for (int i = 0; i < iHeight; ++i) { out[outIndex++] = block[i * jWidth + jColumn]; } } return out; } /** {@inheritDoc} */ @Override public void setColumn(final int column, final T[] array) throws MatrixIndexException, InvalidMatrixException { checkColumnIndex(column); final int nRows = getRowDimension(); if (array.length != nRows) { throw new InvalidMatrixException( "dimensions mismatch: got {0}x{1} but expected {2}x

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>{3}", array.length, 1, nRows, 1); } // perform copy block-wise, to ensure good cache behavior final int jBlock = column / BLOCK_SIZE; final int jColumn = column - jBlock * BLOCK_SIZE; final int jWidth = blockWidth(jBlock); int outIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int iHeight = blockHeight(iBlock); final T[] block = blocks[iBlock * blockColumns + jBlock]; for (int i = 0; i < iHeight; ++i) { block[i * jWidth + jColumn] = array[outIndex++]; } } } /** {@inheritDoc} */ @Override public T getEntry(final int row, final int column) throws MatrixIndexException { try { final int iBlock = row / BLOCK_SIZE; final int jBlock = column / BLOCK_SIZE; final int k = (row - iBlock * BLOCK_SIZE) * blockWidth(jBlock) + (column - jBlock * BLOCK_SIZE); return blocks[iBlock * blockColumns + jBlock][k]; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( "no entry at indices ({0}, {1}) in a {2}x{3} matrix", row, column, getRowDimension(), getColumnDimension()); } } /** {@inheritDoc} */ @Override public void setEntry(final int row, final int column, final T value) throws MatrixIndexException { try { final int iBlock = row / BLOCK_SIZE; final int jBlock = column / BLOCK_SIZE; final int k = (row - iBlock * BLOCK_SIZE) * blockWidth(jBlock) + (column - jBlock * BLOCK_SIZE); blocks[iBlock * blockColumns + jBlock][k] = value; } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( "no entry at indices ({0}, {1}) in a {2}x{3} matrix", row, column, getRowDimension(), getColumnDimension()); } } /** {@inheritDoc} */ @Override public void addToEntry(final int row, final int column, final T increment) throws MatrixIndexException { try { final int iBlock = row / BLOCK_SIZE; final int jBlock = column / BLOCK_SIZE; final int k = (row - iBlock * BLOCK_SIZE) * blockWidth(jBlock) + (column - jBlock * BLOCK_SIZE); final T[] blockIJ = blocks[iBlock * blockColumns + jBlock]; blockIJ[k] = blockIJ[k].add(increment); } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndex

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>Exception( "no entry at indices ({0}, {1}) in a {2}x{3} matrix", row, column, getRowDimension(), getColumnDimension()); } } /** {@inheritDoc} */ @Override public void multiplyEntry(final int row, final int column, final T factor) throws MatrixIndexException { try { final int iBlock = row / BLOCK_SIZE; final int jBlock = column / BLOCK_SIZE; final int k = (row - iBlock * BLOCK_SIZE) * blockWidth(jBlock) + (column - jBlock * BLOCK_SIZE); final T[] blockIJ = blocks[iBlock * blockColumns + jBlock]; blockIJ[k] = blockIJ[k].multiply(factor); } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException( "no entry at indices ({0}, {1}) in a {2}x{3} matrix", row, column, getRowDimension(), getColumnDimension()); } } /** {@inheritDoc} */ @Override public FieldMatrix<T> transpose() { final int nRows = getRowDimension(); final int nCols = getColumnDimension(); final BlockFieldMatrix<T> out = new BlockFieldMatrix<T>(getField(), nCols, nRows); // perform transpose block-wise, to ensure good cache behavior int blockIndex = 0; for (int iBlock = 0; iBlock < blockColumns; ++iBlock) { for (int jBlock = 0; jBlock < blockRows; ++jBlock) { // transpose current block final T[] outBlock = out.blocks[blockIndex]; final T[] tBlock = blocks[jBlock * blockColumns + iBlock]; final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, columns); final int qStart = jBlock * BLOCK_SIZE; final int qEnd = Math.min(qStart + BLOCK_SIZE, rows); int k = 0; for (int p = pStart; p < pEnd; ++p) { final int lInc = pEnd - pStart; int l = p - pStart; for (int q = qStart; q < qEnd; ++q) { outBlock[k] = tBlock[l]; ++k; l+= lInc; } } // go to next block ++blockIndex; } } return out; } /** {@inheritDoc} */ @Override public int getRowDimension() { return rows; } /** {@inheritDoc} */ @Override public int getColumnDimension() { return columns; } /** {@inheritDoc} */ @Override public T[] operate(final T[] v) throws IllegalArgumentException { if (v.

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>length != columns) { throw MathRuntimeException.createIllegalArgumentException( "vector length mismatch: got {0} but expected {1}", v.length, columns); } final T[] out = buildArray(getField(), rows); final T zero = getField().getZero(); // perform multiplication block-wise, to ensure good cache behavior for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final T[] block = blocks[iBlock * blockColumns + jBlock]; final int qStart = jBlock * BLOCK_SIZE; final int qEnd = Math.min(qStart + BLOCK_SIZE, columns); int k = 0; for (int p = pStart; p < pEnd; ++p) { T sum = zero; int q = qStart; while (q < qEnd - 3) { sum = sum. add(block[k].multiply(v[q])). add(block[k + 1].multiply(v[q + 1])). add(block[k + 2].multiply(v[q + 2])). add(block[k + 3].multiply(v[q + 3])); k += 4; q += 4; } while (q < qEnd) { sum = sum.add(block[k++].multiply(v[q++])); } out[p] = out[p].add(sum); } } } return out; } /** {@inheritDoc} */ @Override public T[] preMultiply(final T[] v) throws IllegalArgumentException { if (v.length != rows) { throw MathRuntimeException.createIllegalArgumentException( "vector length mismatch: got {0} but expected {1}", v.length, rows); } final T[] out = buildArray(getField(), columns); final T zero = getField().getZero(); // perform multiplication block-wise, to ensure good cache behavior for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int jWidth = blockWidth(jBlock); final int jWidth2 = jWidth + jWidth; final int jWidth3 = jWidth2 + jWidth; final int jWidth4 = jWidth3 + jWidth; final int qStart = jBlock * BLOCK_SIZE; final int qEnd = Math.min(qStart + BLOCK_SIZE, columns); for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final T[] block = blocks[iBlock * blockColumns + jBlock]; final int

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); for (int q = qStart; q < qEnd; ++q) { int k = q - qStart; T sum = zero; int p = pStart; while (p < pEnd - 3) { sum = sum. add(block[k].multiply(v[p])). add(block[k + jWidth].multiply(v[p + 1])). add(block[k + jWidth2].multiply(v[p + 2])). add(block[k + jWidth3].multiply(v[p + 3])); k += jWidth4; p += 4; } while (p < pEnd) { sum = sum.add(block[k].multiply(v[p++])); k += jWidth; } out[q] = out[q].add(sum); } } } return out; } /** {@inheritDoc} */ @Override public T walkInRowOrder(final FieldMatrixChangingVisitor<T> visitor) throws MatrixVisitorException { visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); for (int p = pStart; p < pEnd; ++p) { for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int jWidth = blockWidth(jBlock); final int qStart = jBlock * BLOCK_SIZE; final int qEnd = Math.min(qStart + BLOCK_SIZE, columns); final T[] block = blocks[iBlock * blockColumns + jBlock]; int k = (p - pStart) * jWidth; for (int q = qStart; q < qEnd; ++q) { block[k] = visitor.visit(p, q, block[k]); ++k; } } } } return visitor.end(); } /** {@inheritDoc} */ @Override public T walkInRowOrder(final FieldMatrixPreservingVisitor<T> visitor) throws MatrixVisitorException { visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); for (int p = pStart; p < pEnd; ++p) {

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int jWidth = blockWidth(jBlock); final int qStart = jBlock * BLOCK_SIZE; final int qEnd = Math.min(qStart + BLOCK_SIZE, columns); final T[] block = blocks[iBlock * blockColumns + jBlock]; int k = (p - pStart) * jWidth; for (int q = qStart; q < qEnd; ++q) { visitor.visit(p, q, block[k]); ++k; } } } } return visitor.end(); } /** {@inheritDoc} */ @Override public T walkInRowOrder(final FieldMatrixChangingVisitor<T> visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException, MatrixVisitorException { checkSubMatrixIndex(startRow, endRow, startColumn, endColumn); visitor.start(rows, columns, startRow, endRow, startColumn, endColumn); for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) { final int p0 = iBlock * BLOCK_SIZE; final int pStart = Math.max(startRow, p0); final int pEnd = Math.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); for (int p = pStart; p < pEnd; ++p) { for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) { final int jWidth = blockWidth(jBlock); final int q0 = jBlock * BLOCK_SIZE; final int qStart = Math.max(startColumn, q0); final int qEnd = Math.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); final T[] block = blocks[iBlock * blockColumns + jBlock]; int k = (p - p0) * jWidth + qStart - q0; for (int q = qStart; q < qEnd; ++q) { block[k] = visitor.visit(p, q, block[k]); ++k; } } } } return visitor.end(); } /** {@inheritDoc} */ @Override public T walkInRowOrder(final FieldMatrixPreservingVisitor<T> visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException, MatrixVisitorException { checkSubMatrixIndex(startRow, endRow, startColumn, endColumn); visitor.start(rows, columns, startRow, endRow, startColumn, endColumn); for (int i

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>Block = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) { final int p0 = iBlock * BLOCK_SIZE; final int pStart = Math.max(startRow, p0); final int pEnd = Math.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); for (int p = pStart; p < pEnd; ++p) { for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) { final int jWidth = blockWidth(jBlock); final int q0 = jBlock * BLOCK_SIZE; final int qStart = Math.max(startColumn, q0); final int qEnd = Math.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); final T[] block = blocks[iBlock * blockColumns + jBlock]; int k = (p - p0) * jWidth + qStart - q0; for (int q = qStart; q < qEnd; ++q) { visitor.visit(p, q, block[k]); ++k; } } } } return visitor.end(); } /** {@inheritDoc} */ @Override public T walkInOptimizedOrder(final FieldMatrixChangingVisitor<T> visitor) throws MatrixVisitorException { visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; final int qEnd = Math.min(qStart + BLOCK_SIZE, columns); final T[] block = blocks[blockIndex]; int k = 0; for (int p = pStart; p < pEnd; ++p) { for (int q = qStart; q < qEnd; ++q) { block[k] = visitor.visit(p, q, block[k]); ++k; } } ++blockIndex; } } return visitor.end(); } /** {@inheritDoc} */ @Override public T walkInOptimizedOrder(final FieldMatrixPreservingVisitor<T> visitor) throws MatrixVisitorException { visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>) { final int pStart = iBlock * BLOCK_SIZE; final int pEnd = Math.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; final int qEnd = Math.min(qStart + BLOCK_SIZE, columns); final T[] block = blocks[blockIndex]; int k = 0; for (int p = pStart; p < pEnd; ++p) { for (int q = qStart; q < qEnd; ++q) { visitor.visit(p, q, block[k]); ++k; } } ++blockIndex; } } return visitor.end(); } /** {@inheritDoc} */ @Override public T walkInOptimizedOrder(final FieldMatrixChangingVisitor<T> visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException, MatrixVisitorException { checkSubMatrixIndex(startRow, endRow, startColumn, endColumn); visitor.start(rows, columns, startRow, endRow, startColumn, endColumn); for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) { final int p0 = iBlock * BLOCK_SIZE; final int pStart = Math.max(startRow, p0); final int pEnd = Math.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) { final int jWidth = blockWidth(jBlock); final int q0 = jBlock * BLOCK_SIZE; final int qStart = Math.max(startColumn, q0); final int qEnd = Math.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); final T[] block = blocks[iBlock * blockColumns + jBlock]; for (int p = pStart; p < pEnd; ++p) { int k = (p - p0) * jWidth + qStart - q0; for (int q = qStart; q < qEnd; ++q) { block[k] = visitor.visit(p, q, block[k]); ++k; } } } } return visitor.end(); } /** {@inheritDoc} */ @Override public T walkInOptimizedOrder(final FieldMatrixPreservingVisitor<T> visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException, MatrixVisitorException { checkSubMatrixIndex(startRow

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>, endRow, startColumn, endColumn); visitor.start(rows, columns, startRow, endRow, startColumn, endColumn); for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) { final int p0 = iBlock * BLOCK_SIZE; final int pStart = Math.max(startRow, p0); final int pEnd = Math.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) { final int jWidth = blockWidth(jBlock); final int q0 = jBlock * BLOCK_SIZE; final int qStart = Math.max(startColumn, q0); final int qEnd = Math.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); final T[] block = blocks[iBlock * blockColumns + jBlock]; for (int p = pStart; p < pEnd; ++p) { int k = (p - p0) * jWidth + qStart - q0; for (int q = qStart; q < qEnd; ++q) { visitor.visit(p, q, block[k]); ++k; } } } } return visitor.end(); } /** * Get the height of a block. * @param blockRow row index (in block sense) of the block * @return height (number of rows) of the block */ private int blockHeight(final int blockRow) { return (blockRow == blockRows - 1) ? rows - blockRow * BLOCK_SIZE : BLOCK_SIZE; } /** * Get the width of a block. * @param blockColumn column index (in block sense) of the block * @return width (number of columns) of the block */ private int blockWidth(final int blockColumn) { return (blockColumn == blockColumns - 1) ? columns - blockColumn * BLOCK_SIZE : BLOCK_SIZE; } }

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> private boolean forward; /** Variation direction around pending event. * (this is considered with respect to the integration direction) */ private boolean increasing; /** Next action indicator. */ private int nextAction; /** Simple constructor. * @param handler event handler * @param maxCheckInterval maximal time interval between switching * function checks (this interval prevents missing sign changes in * case the integration steps becomes very large) * @param convergence convergence threshold in the event time search * @param maxIterationCount upper limit of the iteration count in * the event time search */ public EventState(final EventHandler handler, final double maxCheckInterval, final double convergence, final int maxIterationCount) { this.handler = handler; this.maxCheckInterval = maxCheckInterval; this.convergence = Math.abs(convergence); this.maxIterationCount = maxIterationCount; // some dummy values ... t0 = Double.NaN; g0 = Double.NaN; g0Positive = true; pendingEvent = false; pendingEventTime = Double.NaN; previousEventTime = Double.NaN; increasing = true; nextAction = EventHandler.CONTINUE; } /** Get the underlying event handler. * @return underlying event handler */ public EventHandler getEventHandler() { return handler; } /** Get the maximal time interval between events handler checks. * @return maximal time interval between events handler checks */ public double getMaxCheckInterval() { return maxCheckInterval; } /** Get the convergence threshold for event localization. * @return convergence threshold for event localization */ public double getConvergence() { return convergence; } /** Get the upper limit in the iteration count for event localization. * @return upper limit in the iteration count for event localization */ public int getMaxIterationCount() { return maxIterationCount; } /** Reinitialize the beginning of the step. * @param tStart value of the independent <i>time</i> variable at the * beginning of the step * @param yStart array containing the current value of the state vector * at the beginning of the step * @exception EventException if the event handler * value cannot be evaluated at the beginning of the step */ public void reinitializeBegin(final double tStart, final double[] yStart) throws EventException { t0 = tStart; g0 = handler.g(tStart, yStart); g0Positive = g0 >= 0; } /** Evaluate the impact of the proposed step on the event handler. * @param interpolator step interpolator for the proposed step * @return true if the event handler triggers an event before * the end of the proposed step (this implies the step should be * rejected) * @exception DerivativeException if the interpolator fails to * compute the switching function somewhere within the

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> step * @exception EventException if the switching function * cannot be evaluated * @exception ConvergenceException if an event cannot be located */ public boolean evaluateStep(final StepInterpolator interpolator) throws DerivativeException, EventException, ConvergenceException { try { forward = interpolator.isForward(); final double t1 = interpolator.getCurrentTime(); final int n = Math.max(1, (int) Math.ceil(Math.abs(t1 - t0) / maxCheckInterval)); final double h = (t1 - t0) / n; double ta = t0; double ga = g0; double tb = t0 + (interpolator.isForward() ? convergence : -convergence); for (int i = 0; i < n; ++i) { // evaluate handler value at the end of the substep tb += h; interpolator.setInterpolatedTime(tb); final double gb = handler.g(tb, interpolator.getInterpolatedState()); // check events occurrence if (g0Positive ^ (gb >= 0)) { // there is a sign change: an event is expected during this step if (ga * gb > 0) { // this is a corner case: // - there was an event near ta, // - there is another event between ta and tb // - when ta was computed, convergence was reached on the "wrong side" of the interval // this implies that the real sign of ga is the same as gb, so we need to slightly // shift ta to make sure ga and gb get opposite signs and the solver won't complain // about bracketing final double epsilon = (forward ? 0.25 : -0.25) * convergence; for (int k = 0; (k < 4) && (ga * gb > 0); ++k) { ta += epsilon; interpolator.setInterpolatedTime(ta); ga = handler.g(ta, interpolator.getInterpolatedState()); } if (ga * gb > 0) { // this should never happen throw MathRuntimeException.createInternalError(null); } } // variation direction, with respect to the integration direction increasing = gb >= ga; final UnivariateRealFunction f = new UnivariateRealFunction() { public double value(final double t) throws FunctionEvaluationException { try { interpolator.setInterpolatedTime(t); return handler.g(t, interpolator.getInterpolatedState()); } catch (DerivativeException e) { throw new FunctionEvaluationException(e, t); } catch (EventException e) { throw new FunctionEvaluationException(e, t); } } }; final BrentSolver solver = new BrentSolver(); solver.setAbsoluteAccuracy(convergence); solver.setMaximalIterationCount(maxIterationCount); final double

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> root = (ta <= tb) ? solver.solve(f, ta, tb) : solver.solve(f, tb, ta); if ((Math.abs(root - ta) <= convergence) && (Math.abs(root - previousEventTime) <= convergence)) { // we have either found nothing or found (again ?) a past event, we simply ignore it ta = tb; ga = gb; } else if (Double.isNaN(previousEventTime) || (Math.abs(previousEventTime - root) > convergence)) { pendingEventTime = root; if (pendingEvent && (Math.abs(t1 - pendingEventTime) <= convergence)) { // we were already waiting for this event which was // found during a previous call for a step that was // rejected, this step must now be accepted since it // properly ends exactly at the event occurrence return false; } // either we were not waiting for the event or it has // moved in such a way the step cannot be accepted pendingEvent = true; return true; } } else { // no sign change: there is no event for now ta = tb; ga = gb; } } // no event during the whole step pendingEvent = false; pendingEventTime = Double.NaN; return false; } catch (FunctionEvaluationException e) { final Throwable cause = e.getCause(); if ((cause != null) && (cause instanceof DerivativeException)) { throw (DerivativeException) cause; } else if ((cause != null) && (cause instanceof EventException)) { throw (EventException) cause; } throw new EventException(e); } } /** Get the occurrence time of the event triggered in the current * step. * @return occurrence time of the event triggered in the current * step. */ public double getEventTime() { return pendingEventTime; } /** Acknowledge the fact the step has been accepted by the integrator. * @param t value of the independent <i>time</i> variable at the * end of the step * @param y array containing the current value of the state vector * at the end of the step * @exception EventException if the value of the event * handler cannot be evaluated */ public void stepAccepted(final double t, final double[] y) throws EventException { t0 = t; g0 = handler.g(t, y); if (pendingEvent) { // force the sign to its value "just after the event" previousEventTime = t; g0Positive = increasing; nextAction = handler.eventOccurred(t, y, !(increasing ^ forward)); } else { g0Positive = g0 >= 0; nextAction = EventHandler.CONTINUE; } } /** Check if the integration should be stopped at the end of the *

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.math.ode.nonstiff; import org.apache.commons.math.linear.Array2DRowRealMatrix; import org.apache.commons.math.ode.DerivativeException; import org.apache.commons.math.ode.FirstOrderDifferentialEquations; import org.apache.commons.math.ode.IntegratorException; import org.apache.commons.math.ode.MultistepIntegrator; /** Base class for {@link AdamsBashforthIntegrator Adams-Bashforth} and * {@link AdamsMoultonIntegrator Adams-Moulton} integrators. * @version $Revision$ $Date$ * @since 2.0 */ public abstract class AdamsIntegrator extends MultistepIntegrator { /** Transformer. */ private final AdamsNordsieckTransformer transformer; /** * Build an Adams integrator with the given order and step control prameters. * @param name name of the method * @param nSteps number of steps of the method excluding the one being computed * @param order order of the method * @param minStep minimal step (must be positive even for backward * integration), the last step can be smaller than this * @param maxStep maximal step (must be positive even for backward * integration) * @param scalAbsoluteTolerance allowed absolute error * @param scalRelativeTolerance allowed relative error * @exception IllegalArgumentException if order is 1 or less */ public AdamsIntegrator(final String name, final int nSteps, final int order, final double minStep, final double maxStep, final double scalAbsoluteTolerance, final double scalRelativeTolerance) throws IllegalArgumentException { super(name, nSteps, order, minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); transformer = AdamsNordsieckTransformer.getInstance(nSteps); } /** * Build an Adams integrator with the given order and step control parameters. * @param name name of the method * @param nSteps number of steps of the method excluding the one

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> being computed * @param order order of the method * @param minStep minimal step (must be positive even for backward * integration), the last step can be smaller than this * @param maxStep maximal step (must be positive even for backward * integration) * @param vecAbsoluteTolerance allowed absolute error * @param vecRelativeTolerance allowed relative error * @exception IllegalArgumentException if order is 1 or less */ public AdamsIntegrator(final String name, final int nSteps, final int order, final double minStep, final double maxStep, final double[] vecAbsoluteTolerance, final double[] vecRelativeTolerance) throws IllegalArgumentException { super(name, nSteps, order, minStep, maxStep, vecAbsoluteTolerance, vecRelativeTolerance); transformer = AdamsNordsieckTransformer.getInstance(nSteps); } /** {@inheritDoc} */ @Override public abstract double integrate(final FirstOrderDifferentialEquations equations, final double t0, final double[] y0, final double t, final double[] y) throws DerivativeException, IntegratorException; /** {@inheritDoc} */ @Override protected Array2DRowRealMatrix initializeHighOrderDerivatives(final double[] first, final double[][] multistep) { return transformer.initializeHighOrderDerivatives(first, multistep); } /** Update the high order scaled derivatives for Adams integrators (phase 1). * <p>The complete update of high order derivatives has a form similar to: * <pre> * r<sub>n+1</sub> = (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u + P<sup>-1</sup> A P r<sub>n</sub> * </pre> * this method computes the P<sup>-1</sup> A P r<sub>n</sub> part.</p> * @param highOrder high order scaled derivatives * (h<sup>2</sup>/2 y'', ... h<sup>k</sup>/k! y(k)) * @return updated high order derivatives * @see #updateHighOrderDerivativesPhase2(double[], double[], Array2DRowRealMatrix) */ public Array2DRowRealMatrix updateHighOrderDerivativesPhase1(final Array2DRowRealMatrix highOrder) { return transformer.updateHighOrderDerivativesPhase1(highOrder); } /** Update the high order scaled derivatives Adams integrators (phase 2). * <p>The complete update of high order derivatives has a form similar to: * <pre> * r<sub>n+1</sub> = (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u + P<sup>-1</sup> A P r

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.math.ode; /** * This class is used in the junit tests for the ODE integrators. * <p>This specific problem is the following differential equation : * <pre> * y' = 3x^5 - y * </pre> * when the initial condition is y(0) = -360, the solution of this * equation degenerates to a simple quintic polynomial function : * <pre> * y (t) = 3x^5 - 15x^4 + 60x^3 - 180x^2 + 360x - 360 * </pre> * </p> */ public class TestProblem6 extends TestProblemAbstract { /** Serializable version identifier. */ private static final long serialVersionUID = 1353409119804352378L; /** theoretical state */ private double[] y; /** * Simple constructor. */ public TestProblem6() { super(); double[] y0 = { -360.0 }; setInitialConditions(0.0, y0); setFinalConditions(1.0); double[] errorScale = { 1.0 }; setErrorScale(errorScale); y = new double[y0.length]; } /** * Copy constructor. * @param problem problem to copy */ public TestProblem6(TestProblem6 problem) { super(problem); y = problem.y.clone(); } /** {@inheritDoc} */ @Override public TestProblem6 copy() { return new TestProblem6(this); } @Override public void doComputeDerivatives(double t, double[] y, double[] yDot) { // compute the derivatives double t2 = t * t; double t4 = t2 * t2; double t5 = t4 * t; for (int i = 0; i < n; ++i) { yDot[i] = 3

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> * t5 - y[i]; } } @Override public double[] computeTheoreticalState(double t) { for (int i = 0; i < n; ++i) { y[i] = ((((3 * t - 15) * t + 60) * t - 180) * t + 360) * t - 360; } return y; } }

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.math.ode.nonstiff; import org.apache.commons.math.ode.AbstractIntegrator; import org.apache.commons.math.ode.DerivativeException; import org.apache.commons.math.ode.FirstOrderDifferentialEquations; import org.apache.commons.math.ode.IntegratorException; /** * This abstract class holds the common part of all adaptive * stepsize integrators for Ordinary Differential Equations. * * <p>These algorithms perform integration with stepsize control, which * means the user does not specify the integration step but rather a * tolerance on error. The error threshold is computed as * <pre> * threshold_i = absTol_i + relTol_i * max (abs (ym), abs (ym+1)) * </pre> * where absTol_i is the absolute tolerance for component i of the * state vector and relTol_i is the relative tolerance for the same * component. The user can also use only two scalar values absTol and * relTol which will be used for all components.</p> * * <p>If the estimated error for ym+1 is such that * <pre> * sqrt((sum (errEst_i / threshold_i)^2 ) / n) < 1 * </pre> * * (where n is the state vector dimension) then the step is accepted, * otherwise the step is rejected and a new attempt is made with a new * stepsize.</p> * * @version $Revision$ $Date$ * @since 1.2 * */ public abstract class AdaptiveStepsizeIntegrator extends AbstractIntegrator { /** Allowed absolute scalar error. */ protected final double scalAbsoluteTolerance; /** Allowed relative scalar error. */ protected final double scalRelativeTolerance; /** Allowed absolute vectorial error. */ protected final double[] vecAbsoluteTolerance; /** Allowed relative vectorial error. */ protected final double[] vecRelativeTolerance; /** User supplied initial step. */ private

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> double initialStep; /** Minimal step. */ private final double minStep; /** Maximal step. */ private final double maxStep; /** Build an integrator with the given stepsize bounds. * The default step handler does nothing. * @param name name of the method * @param minStep minimal step (must be positive even for backward * integration), the last step can be smaller than this * @param maxStep maximal step (must be positive even for backward * integration) * @param scalAbsoluteTolerance allowed absolute error * @param scalRelativeTolerance allowed relative error */ public AdaptiveStepsizeIntegrator(final String name, final double minStep, final double maxStep, final double scalAbsoluteTolerance, final double scalRelativeTolerance) { super(name); this.minStep = Math.abs(minStep); this.maxStep = Math.abs(maxStep); this.initialStep = -1.0; this.scalAbsoluteTolerance = scalAbsoluteTolerance; this.scalRelativeTolerance = scalRelativeTolerance; this.vecAbsoluteTolerance = null; this.vecRelativeTolerance = null; resetInternalState(); } /** Build an integrator with the given stepsize bounds. * The default step handler does nothing. * @param name name of the method * @param minStep minimal step (must be positive even for backward * integration), the last step can be smaller than this * @param maxStep maximal step (must be positive even for backward * integration) * @param vecAbsoluteTolerance allowed absolute error * @param vecRelativeTolerance allowed relative error */ public AdaptiveStepsizeIntegrator(final String name, final double minStep, final double maxStep, final double[] vecAbsoluteTolerance, final double[] vecRelativeTolerance) { super(name); this.minStep = minStep; this.maxStep = maxStep; this.initialStep = -1.0; this.scalAbsoluteTolerance = 0; this.scalRelativeTolerance = 0; this.vecAbsoluteTolerance = vecAbsoluteTolerance.clone(); this.vecRelativeTolerance = vecRelativeTolerance.clone(); resetInternalState(); } /** Set the initial step size. * <p>This method allows the user to specify an initial positive * step size instead of letting the integrator guess it by * itself. If this method is not called before integration is * started, the initial step size will be estimated by the * integrator.</p> * @param initialStepSize initial step size to use (must be positive even * for backward integration ; providing a negative value or a value * outside of the min/max step interval will lead the integrator to * ignore the value and compute the initial step size by itself) */ public void setInitialStepSize(final double initialStepSize) { if ((initialStepSize < minStep)

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> || (initialStepSize > maxStep)) { initialStep = -1.0; } else { initialStep = initialStepSize; } } /** Perform some sanity checks on the integration parameters. * @param equations differential equations set * @param t0 start time * @param y0 state vector at t0 * @param t target time for the integration * @param y placeholder where to put the state vector * @exception IntegratorException if some inconsistency is detected */ @Override protected void sanityChecks(final FirstOrderDifferentialEquations equations, final double t0, final double[] y0, final double t, final double[] y) throws IntegratorException { super.sanityChecks(equations, t0, y0, t, y); if ((vecAbsoluteTolerance != null) && (vecAbsoluteTolerance.length != y0.length)) { throw new IntegratorException( "dimensions mismatch: state vector has dimension {0}," + " absolute tolerance vector has dimension {1}", y0.length, vecAbsoluteTolerance.length); } if ((vecRelativeTolerance != null) && (vecRelativeTolerance.length != y0.length)) { throw new IntegratorException( "dimensions mismatch: state vector has dimension {0}," + " relative tolerance vector has dimension {1}", y0.length, vecRelativeTolerance.length); } } /** Initialize the integration step. * @param equations differential equations set * @param forward forward integration indicator * @param order order of the method * @param scale scaling vector for the state vector * @param t0 start time * @param y0 state vector at t0 * @param yDot0 first time derivative of y0 * @param y1 work array for a state vector * @param yDot1 work array for the first time derivative of y1 * @return first integration step * @exception DerivativeException this exception is propagated to * the caller if the underlying user function triggers one */ public double initializeStep(final FirstOrderDifferentialEquations equations, final boolean forward, final int order, final double[] scale, final double t0, final double[] y0, final double[] yDot0, final double[] y1, final double[] yDot1) throws DerivativeException { if (initialStep > 0) { // use the user provided value return forward ? initialStep : -initialStep; } // very rough first guess : h = 0.01 * ||y/scale|| / ||y'/scale|| // this guess will be used to perform an Euler step double ratio; double yOnScale2 = 0; double yDotOnScale2 = 0; for (int j = 0; j < y0.length; ++j) { ratio = y0[j] / scale[j]; yOn

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>Scale2 += ratio * ratio; ratio = yDot0[j] / scale[j]; yDotOnScale2 += ratio * ratio; } double h = ((yOnScale2 < 1.0e-10) || (yDotOnScale2 < 1.0e-10)) ? 1.0e-6 : (0.01 * Math.sqrt(yOnScale2 / yDotOnScale2)); if (! forward) { h = -h; } // perform an Euler step using the preceding rough guess for (int j = 0; j < y0.length; ++j) { y1[j] = y0[j] + h * yDot0[j]; } computeDerivatives(t0 + h, y1, yDot1); // estimate the second derivative of the solution double yDDotOnScale = 0; for (int j = 0; j < y0.length; ++j) { ratio = (yDot1[j] - yDot0[j]) / scale[j]; yDDotOnScale += ratio * ratio; } yDDotOnScale = Math.sqrt(yDDotOnScale) / h; // step size is computed such that // h^order * max (||y'/tol||, ||y''/tol||) = 0.01 final double maxInv2 = Math.max(Math.sqrt(yDotOnScale2), yDDotOnScale); final double h1 = (maxInv2 < 1.0e-15) ? Math.max(1.0e-6, 0.001 * Math.abs(h)) : Math.pow(0.01 / maxInv2, 1.0 / order); h = Math.min(100.0 * Math.abs(h), h1); h = Math.max(h, 1.0e-12 * Math.abs(t0)); // avoids cancellation when computing t1 - t0 if (h < getMinStep()) { h = getMinStep(); } if (h > getMaxStep()) { h = getMaxStep(); } if (! forward) { h = -h; } return h; } /** Filter the integration step. * @param h signed step * @param forward forward integration indicator * @param acceptSmall if true, steps smaller than the minimal value * are silently increased up to this value, if false such small * steps generate an exception * @return a bounded integration step (h if no bound is reach, or a bounded value) * @exception IntegratorException if the step is too small and acceptSmall is false */ protected double filterStep(final double h, final boolean forward, final boolean acceptSmall) throws IntegratorException {

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> double filteredH = h; if (Math.abs(h) < minStep) { if (acceptSmall) { filteredH = forward ? minStep : -minStep; } else { throw new IntegratorException( "minimal step size ({0,number,0.00E00}) reached, integration needs {1,number,0.00E00}", minStep, Math.abs(h)); } } if (filteredH > maxStep) { filteredH = maxStep; } else if (filteredH < -maxStep) { filteredH = -maxStep; } return filteredH; } /** {@inheritDoc} */ public abstract double integrate (FirstOrderDifferentialEquations equations, double t0, double[] y0, double t, double[] y) throws DerivativeException, IntegratorException; /** {@inheritDoc} */ @Override public double getCurrentStepStart() { return stepStart; } /** Reset internal state to dummy values. */ protected void resetInternalState() { stepStart = Double.NaN; stepSize = Math.sqrt(minStep * maxStep); } /** Get the minimal step. * @return minimal step */ public double getMinStep() { return minStep; } /** Get the maximal step. * @return maximal step */ public double getMaxStep() { return maxStep; } }

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>> * * @version $Revision$ $Date$ * @since 1.2 */ public class DormandPrince853Integrator extends EmbeddedRungeKuttaIntegrator { /** Integrator method name. */ private static final String METHOD_NAME = "Dormand-Prince 8 (5, 3)"; /** Time steps Butcher array. */ private static final double[] STATIC_C = { (12.0 - 2.0 * Math.sqrt(6.0)) / 135.0, (6.0 - Math.sqrt(6.0)) / 45.0, (6.0 - Math.sqrt(6.0)) / 30.0, (6.0 + Math.sqrt(6.0)) / 30.0, 1.0/3.0, 1.0/4.0, 4.0/13.0, 127.0/195.0, 3.0/5.0, 6.0/7.0, 1.0, 1.0 }; /** Internal weights Butcher array. */ private static final double[][] STATIC_A = { // k2 {(12.0 - 2.0 * Math.sqrt(6.0)) / 135.0}, // k3 {(6.0 - Math.sqrt(6.0)) / 180.0, (6.0 - Math.sqrt(6.0)) / 60.0}, // k4 {(6.0 - Math.sqrt(6.0)) / 120.0, 0.0, (6.0 - Math.sqrt(6.0)) / 40.0}, // k5 {(462.0 + 107.0 * Math.sqrt(6.0)) / 3000.0, 0.0, (-402.0 - 197.0 * Math.sqrt(6.0)) / 1000.0, (168.0 + 73.0 * Math.sqrt(6.0)) / 375.0}, // k6 {1.0 / 27.0, 0.0, 0.0, (16.0 + Math.sqrt(6.0)) / 108.0, (16.0 - Math.sqrt(6.0)) / 108.0}, // k7 {19.0 / 512.0, 0.0, 0.0, (118.0 + 23.0 * Math.sqrt(6.0)) / 1024.0, (118.0 - 23.0 * Math.

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>sqrt(6.0)) / 1024.0, -9.0 / 512.0}, // k8 {13772.0 / 371293.0, 0.0, 0.0, (51544.0 + 4784.0 * Math.sqrt(6.0)) / 371293.0, (51544.0 - 4784.0 * Math.sqrt(6.0)) / 371293.0, -5688.0 / 371293.0, 3072.0 / 371293.0}, // k9 {58656157643.0 / 93983540625.0, 0.0, 0.0, (-1324889724104.0 - 318801444819.0 * Math.sqrt(6.0)) / 626556937500.0, (-1324889724104.0 + 318801444819.0 * Math.sqrt(6.0)) / 626556937500.0, 96044563816.0 / 3480871875.0, 5682451879168.0 / 281950621875.0, -165125654.0 / 3796875.0}, // k10 {8909899.0 / 18653125.0, 0.0, 0.0, (-4521408.0 - 1137963.0 * Math.sqrt(6.0)) / 2937500.0, (-4521408.0 + 1137963.0 * Math.sqrt(6.0)) / 2937500.0, 96663078.0 / 4553125.0, 2107245056.0 / 137915625.0, -4913652016.0 / 147609375.0, -78894270.0 / 3880452869.0}, // k

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>11 {-20401265806.0 / 21769653311.0, 0.0, 0.0, (354216.0 + 94326.0 * Math.sqrt(6.0)) / 112847.0, (354216.0 - 94326.0 * Math.sqrt(6.0)) / 112847.0, -43306765128.0 / 5313852383.0, -20866708358144.0 / 1126708119789.0, 14886003438020.0 / 654632330667.0, 35290686222309375.0 / 14152473387134411.0, -1477884375.0 / 485066827.0}, // k12 {39815761.0 / 17514443.0, 0.0, 0.0, (-3457480.0 - 960905.0 * Math.sqrt(6.0)) / 551636.0, (-3457480.0 + 960905.0 * Math.sqrt(6.0)) / 551636.0, -844554132.0 / 47026969.0, 8444996352.0 / 302158619.0, -2509602342.0 / 877790785.0, -28388795297996250.0 / 3199510091356783.0, 226716250.0 / 18341897.0, 1371316744.0 / 2131383595.0}, // k13 should be for interpolation only, but since it is the same // stage as the first evaluation of the next step, we perform it // here at no cost by specifying this is an fsal method {104257.0/1920240.

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> @param minStep minimal step (must be positive even for backward * integration), the last step can be smaller than this * @param maxStep maximal step (must be positive even for backward * integration) * @param scalAbsoluteTolerance allowed absolute error * @param scalRelativeTolerance allowed relative error */ public DormandPrince853Integrator(final double minStep, final double maxStep, final double scalAbsoluteTolerance, final double scalRelativeTolerance) { super(METHOD_NAME, true, STATIC_C, STATIC_A, STATIC_B, new DormandPrince853StepInterpolator(), minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); } /** Simple constructor. * Build an eighth order Dormand-Prince integrator with the given step bounds * @param minStep minimal step (must be positive even for backward * integration), the last step can be smaller than this * @param maxStep maximal step (must be positive even for backward * integration) * @param vecAbsoluteTolerance allowed absolute error * @param vecRelativeTolerance allowed relative error */ public DormandPrince853Integrator(final double minStep, final double maxStep, final double[] vecAbsoluteTolerance, final double[] vecRelativeTolerance) { super(METHOD_NAME, true, STATIC_C, STATIC_A, STATIC_B, new DormandPrince853StepInterpolator(), minStep, maxStep, vecAbsoluteTolerance, vecRelativeTolerance); } /** {@inheritDoc} */ @Override public int getOrder() { return 8; } /** {@inheritDoc} */ @Override protected double estimateError(final double[][] yDotK, final double[] y0, final double[] y1, final double h) { double error1 = 0; double error2 = 0; for (int j = 0; j < y0.length; ++j) { final double errSum1 = E1_01 * yDotK[0][j] + E1_06 * yDotK[5][j] + E1_07 * yDotK[6][j] + E1_08 * yDotK[7][j] + E1_09 * yDotK[8][j] + E1_10 * yDotK[9][j] + E1_11 * yDotK[10][j] + E1_12 * yDotK[11][j]; final double errSum2 = E2_01 * yDotK[0][j] + E2_06 * yDotK[5][j] + E2_07 * yDotK[6][j] + E2_08 * yDotK[7][j] + E2_09 *

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> yDotK[8][j] + E2_10 * yDotK[9][j] + E2_11 * yDotK[10][j] + E2_12 * yDotK[11][j]; final double yScale = Math.max(Math.abs(y0[j]), Math.abs(y1[j])); final double tol = (vecAbsoluteTolerance == null) ? (scalAbsoluteTolerance + scalRelativeTolerance * yScale) : (vecAbsoluteTolerance[j] + vecRelativeTolerance[j] * yScale); final double ratio1 = errSum1 / tol; error1 += ratio1 * ratio1; final double ratio2 = errSum2 / tol; error2 += ratio2 * ratio2; } double den = error1 + 0.01 * error2; if (den <= 0.0) { den = 1.0; } return Math.abs(h) * error1 / Math.sqrt(y0.length * den); } }

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>; row < rowCount; ++row) { for (int col = 0; col < columnCount; ++col) { out.setEntry(row, col, getEntry(row, col) + m.getEntry(row, col)); } } return out; } /** {@inheritDoc} */ public RealMatrix subtract(final RealMatrix m) throws IllegalArgumentException { // safety check MatrixUtils.checkSubtractionCompatible(this, m); final int rowCount = getRowDimension(); final int columnCount = getColumnDimension(); final RealMatrix out = createMatrix(rowCount, columnCount); for (int row = 0; row < rowCount; ++row) { for (int col = 0; col < columnCount; ++col) { out.setEntry(row, col, getEntry(row, col) - m.getEntry(row, col)); } } return out; } /** {@inheritDoc} */ public RealMatrix scalarAdd(final double d) { final int rowCount = getRowDimension(); final int columnCount = getColumnDimension(); final RealMatrix out = createMatrix(rowCount, columnCount); for (int row = 0; row < rowCount; ++row) { for (int col = 0; col < columnCount; ++col) { out.setEntry(row, col, getEntry(row, col) + d); } } return out; } /** {@inheritDoc} */ public RealMatrix scalarMultiply(final double d) { final int rowCount = getRowDimension(); final int columnCount = getColumnDimension(); final RealMatrix out = createMatrix(rowCount, columnCount); for (int row = 0; row < rowCount; ++row) { for (int col = 0; col < columnCount; ++col) { out.setEntry(row, col, getEntry(row, col) * d); } } return out; } /** {@inheritDoc} */ public RealMatrix multiply(final RealMatrix m) throws IllegalArgumentException { // safety check MatrixUtils.checkMultiplicationCompatible(this, m); final int nRows = getRowDimension(); final int nCols = m.getColumnDimension(); final int nSum = getColumnDimension(); final RealMatrix out = createMatrix(nRows, nCols); for (int row = 0; row < nRows; ++row) { for (int col = 0; col < nCols; ++col) { double sum = 0; for (int i = 0; i < nSum; ++i) { sum += getEntry(row, i) * m.getEntry(i, col); } out.setEntry(row, col, sum); } } return out; } /** {@inheritDoc} */ public RealMatrix preMultiply(final RealMatrix m

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>) throws IllegalArgumentException { return m.multiply(this); } /** {@inheritDoc} */ public double[][] getData() { final double[][] data = new double[getRowDimension()][getColumnDimension()]; for (int i = 0; i < data.length; ++i) { final double[] dataI = data[i]; for (int j = 0; j < dataI.length; ++j) { dataI[j] = getEntry(i, j); } } return data; } /** {@inheritDoc} */ public double getNorm() { return walkInColumnOrder(new RealMatrixPreservingVisitor() { /** Last row index. */ private double endRow; /** Sum of absolute values on one column. */ private double columnSum; /** Maximal sum across all columns. */ private double maxColSum; /** {@inheritDoc} */ public void start(final int rows, final int columns, final int startRow, final int endRow, final int startColumn, final int endColumn) { this.endRow = endRow; columnSum = 0; maxColSum = 0; } /** {@inheritDoc} */ public void visit(final int row, final int column, final double value) { columnSum += Math.abs(value); if (row == endRow) { maxColSum = Math.max(maxColSum, columnSum); columnSum = 0; } } /** {@inheritDoc} */ public double end() { return maxColSum; } }); } /** {@inheritDoc} */ public double getFrobeniusNorm() { return walkInOptimizedOrder(new RealMatrixPreservingVisitor() { /** Sum of squared entries. */ private double sum; /** {@inheritDoc} */ public void start(final int rows, final int columns, final int startRow, final int endRow, final int startColumn, final int endColumn) { sum = 0; } /** {@inheritDoc} */ public void visit(final int row, final int column, final double value) { sum += value * value; } /** {@inheritDoc} */ public double end() { return Math.sqrt(sum); } }); } /** {@inheritDoc} */ public RealMatrix getSubMatrix(final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException { MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn); final RealMatrix subMatrix = createMatrix(endRow - startRow + 1, endColumn - startColumn + 1); for (int i = startRow; i <= endRow; ++i) { for (int j = startColumn; j <= endColumn; ++j) { subMatrix.setEntry(i - startRow

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>, j - startColumn, getEntry(i, j)); } } return subMatrix; } /** {@inheritDoc} */ public RealMatrix getSubMatrix(final int[] selectedRows, final int[] selectedColumns) throws MatrixIndexException { // safety checks MatrixUtils.checkSubMatrixIndex(this, selectedRows, selectedColumns); // copy entries final RealMatrix subMatrix = createMatrix(selectedRows.length, selectedColumns.length); subMatrix.walkInOptimizedOrder(new DefaultRealMatrixChangingVisitor() { /** {@inheritDoc} */ @Override public double visit(final int row, final int column, final double value) { return getEntry(selectedRows[row], selectedColumns[column]); } }); return subMatrix; } /** {@inheritDoc} */ public void copySubMatrix(final int startRow, final int endRow, final int startColumn, final int endColumn, final double[][] destination) throws MatrixIndexException, IllegalArgumentException { // safety checks MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn); final int rowsCount = endRow + 1 - startRow; final int columnsCount = endColumn + 1 - startColumn; if ((destination.length < rowsCount) || (destination[0].length < columnsCount)) { throw MathRuntimeException.createIllegalArgumentException( "dimensions mismatch: got {0}x{1} but expected {2}x{3}", destination.length, destination[0].length, rowsCount, columnsCount); } // copy entries walkInOptimizedOrder(new DefaultRealMatrixPreservingVisitor() { /** Initial row index. */ private int startRow; /** Initial column index. */ private int startColumn; /** {@inheritDoc} */ @Override public void start(final int rows, final int columns, final int startRow, final int endRow, final int startColumn, final int endColumn) { this.startRow = startRow; this.startColumn = startColumn; } /** {@inheritDoc} */ @Override public void visit(final int row, final int column, final double value) { destination[row - startRow][column - startColumn] = value; } }, startRow, endRow, startColumn, endColumn); } /** {@inheritDoc} */ public void copySubMatrix(int[] selectedRows, int[] selectedColumns, double[][] destination) throws MatrixIndexException, IllegalArgumentException { // safety checks MatrixUtils.checkSubMatrixIndex(this, selectedRows, selectedColumns); if ((destination.length < selectedRows.length) || (destination[0].length < selectedColumns.length)) { throw MathRuntimeException.createIllegalArgumentException( "dimensions mismatch: got {0}x{1} but expected {2}x{3}", destination.length, destination[0].length, selectedRows.

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>length, selectedColumns.length); } // copy entries for (int i = 0; i < selectedRows.length; i++) { final double[] destinationI = destination[i]; for (int j = 0; j < selectedColumns.length; j++) { destinationI[j] = getEntry(selectedRows[i], selectedColumns[j]); } } } /** {@inheritDoc} */ public void setSubMatrix(final double[][] subMatrix, final int row, final int column) throws MatrixIndexException { final int nRows = subMatrix.length; if (nRows == 0) { throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row"); } final int nCols = subMatrix[0].length; if (nCols == 0) { throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column"); } for (int r = 1; r < nRows; ++r) { if (subMatrix[r].length != nCols) { throw MathRuntimeException.createIllegalArgumentException( "some rows have length {0} while others have length {1}", nCols, subMatrix[r].length); } } MatrixUtils.checkRowIndex(this, row); MatrixUtils.checkColumnIndex(this, column); MatrixUtils.checkRowIndex(this, nRows + row - 1); MatrixUtils.checkColumnIndex(this, nCols + column - 1); for (int i = 0; i < nRows; ++i) { for (int j = 0; j < nCols; ++j) { setEntry(row + i, column + j, subMatrix[i][j]); } } lu = null; } /** {@inheritDoc} */ public RealMatrix getRowMatrix(final int row) throws MatrixIndexException { MatrixUtils.checkRowIndex(this, row); final int nCols = getColumnDimension(); final RealMatrix out = createMatrix(1, nCols); for (int i = 0; i < nCols; ++i) { out.setEntry(0, i, getEntry(row, i)); } return out; } /** {@inheritDoc} */ public void setRowMatrix(final int row, final RealMatrix matrix) throws MatrixIndexException, InvalidMatrixException { MatrixUtils.checkRowIndex(this, row); final int nCols = getColumnDimension(); if ((matrix.getRowDimension() != 1) || (matrix.getColumnDimension() != nCols)) { throw new InvalidMatrixException( "dimensions mismatch: got {0}x{1} but expected {2}x{3}", matrix.getRowDimension(), matrix.getColumnDimension(), 1, nCols); } for (int i = 0; i < nCols; ++i) { setEntry(row, i, matrix.

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>getEntry(0, i)); } } /** {@inheritDoc} */ public RealMatrix getColumnMatrix(final int column) throws MatrixIndexException { MatrixUtils.checkColumnIndex(this, column); final int nRows = getRowDimension(); final RealMatrix out = createMatrix(nRows, 1); for (int i = 0; i < nRows; ++i) { out.setEntry(i, 0, getEntry(i, column)); } return out; } /** {@inheritDoc} */ public void setColumnMatrix(final int column, final RealMatrix matrix) throws MatrixIndexException, InvalidMatrixException { MatrixUtils.checkColumnIndex(this, column); final int nRows = getRowDimension(); if ((matrix.getRowDimension() != nRows) || (matrix.getColumnDimension() != 1)) { throw new InvalidMatrixException( "dimensions mismatch: got {0}x{1} but expected {2}x{3}", matrix.getRowDimension(), matrix.getColumnDimension(), nRows, 1); } for (int i = 0; i < nRows; ++i) { setEntry(i, column, matrix.getEntry(i, 0)); } } /** {@inheritDoc} */ public RealVector getRowVector(final int row) throws MatrixIndexException { return new ArrayRealVector(getRow(row), false); } /** {@inheritDoc} */ public void setRowVector(final int row, final RealVector vector) throws MatrixIndexException, InvalidMatrixException { MatrixUtils.checkRowIndex(this, row); final int nCols = getColumnDimension(); if (vector.getDimension() != nCols) { throw new InvalidMatrixException( "dimensions mismatch: got {0}x{1} but expected {2}x{3}", 1, vector.getDimension(), 1, nCols); } for (int i = 0; i < nCols; ++i) { setEntry(row, i, vector.getEntry(i)); } } /** {@inheritDoc} */ public RealVector getColumnVector(final int column) throws MatrixIndexException { return new ArrayRealVector(getColumn(column), false); } /** {@inheritDoc} */ public void setColumnVector(final int column, final RealVector vector) throws MatrixIndexException, InvalidMatrixException { MatrixUtils.checkColumnIndex(this, column); final int nRows = getRowDimension(); if (vector.getDimension() != nRows) { throw new InvalidMatrixException( "dimensions mismatch: got {0}x{1} but expected {2}x{3}", vector.getDimension(), 1, nRows, 1); } for (int i = 0; i < nRows; ++i) { setEntry(i, column, vector.getEntry(i));

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> } } /** {@inheritDoc} */ public double[] getRow(final int row) throws MatrixIndexException { MatrixUtils.checkRowIndex(this, row); final int nCols = getColumnDimension(); final double[] out = new double[nCols]; for (int i = 0; i < nCols; ++i) { out[i] = getEntry(row, i); } return out; } /** {@inheritDoc} */ public void setRow(final int row, final double[] array) throws MatrixIndexException, InvalidMatrixException { MatrixUtils.checkRowIndex(this, row); final int nCols = getColumnDimension(); if (array.length != nCols) { throw new InvalidMatrixException( "dimensions mismatch: got {0}x{1} but expected {2}x{3}", 1, array.length, 1, nCols); } for (int i = 0; i < nCols; ++i) { setEntry(row, i, array[i]); } } /** {@inheritDoc} */ public double[] getColumn(final int column) throws MatrixIndexException { MatrixUtils.checkColumnIndex(this, column); final int nRows = getRowDimension(); final double[] out = new double[nRows]; for (int i = 0; i < nRows; ++i) { out[i] = getEntry(i, column); } return out; } /** {@inheritDoc} */ public void setColumn(final int column, final double[] array) throws MatrixIndexException, InvalidMatrixException { MatrixUtils.checkColumnIndex(this, column); final int nRows = getRowDimension(); if (array.length != nRows) { throw new InvalidMatrixException( "dimensions mismatch: got {0}x{1} but expected {2}x{3}", array.length, 1, nRows, 1); } for (int i = 0; i < nRows; ++i) { setEntry(i, column, array[i]); } } /** {@inheritDoc} */ public abstract double getEntry(int row, int column) throws MatrixIndexException; /** {@inheritDoc} */ public abstract void setEntry(int row, int column, double value) throws MatrixIndexException; /** {@inheritDoc} */ public abstract void addToEntry(int row, int column, double increment) throws MatrixIndexException; /** {@inheritDoc} */ public abstract void multiplyEntry(int row, int column, double factor) throws MatrixIndexException; /** {@inheritDoc} */ public RealMatrix transpose() { final int nRows = getRowDimension(); final int nCols = getColumnDimension(); final RealMatrix out = createMatrix(nCols, nRows); walkInOptimizedOrder(new DefaultRealMatrixPreservingVisitor() {

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> /** {@inheritDoc} */ @Override public void visit(final int row, final int column, final double value) { out.setEntry(column, row, value); } }); return out; } /** {@inheritDoc} */ @Deprecated public RealMatrix inverse() throws InvalidMatrixException { if (lu == null) { lu = new LUDecompositionImpl(this, MathUtils.SAFE_MIN).getSolver(); } return lu.getInverse(); } /** {@inheritDoc} */ @Deprecated public double getDeterminant() throws InvalidMatrixException { return new LUDecompositionImpl(this, MathUtils.SAFE_MIN).getDeterminant(); } /** {@inheritDoc} */ public boolean isSquare() { return getColumnDimension() == getRowDimension(); } /** {@inheritDoc} */ @Deprecated public boolean isSingular() { if (lu == null) { lu = new LUDecompositionImpl(this, MathUtils.SAFE_MIN).getSolver(); } return !lu.isNonSingular(); } /** {@inheritDoc} */ public abstract int getRowDimension(); /** {@inheritDoc} */ public abstract int getColumnDimension(); /** {@inheritDoc} */ public double getTrace() throws NonSquareMatrixException { final int nRows = getRowDimension(); final int nCols = getColumnDimension(); if (nRows != nCols) { throw new NonSquareMatrixException(nRows, nCols); } double trace = 0; for (int i = 0; i < nRows; ++i) { trace += getEntry(i, i); } return trace; } /** {@inheritDoc} */ public double[] operate(final double[] v) throws IllegalArgumentException { final int nRows = getRowDimension(); final int nCols = getColumnDimension(); if (v.length != nCols) { throw MathRuntimeException.createIllegalArgumentException( "vector length mismatch: got {0} but expected {1}", v.length, nCols); } final double[] out = new double[nRows]; for (int row = 0; row < nRows; ++row) { double sum = 0; for (int i = 0; i < nCols; ++i) { sum += getEntry(row, i) * v[i]; } out[row] = sum; } return out; } /** {@inheritDoc} */ public RealVector operate(final RealVector v) throws IllegalArgumentException { try { return new ArrayRealVector(operate(((ArrayRealVector) v).getDataRef()), false); } catch (ClassCastException cce) { final int nRows = getRowDimension(); final int nCols = getColumnDimension(); if (v.getDimension() != nCols) { throw MathRuntimeException.createIllegalArgumentException( "vector length mismatch: got {

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS>0} but expected {1}", v.getDimension(), nCols); } final double[] out = new double[nRows]; for (int row = 0; row < nRows; ++row) { double sum = 0; for (int i = 0; i < nCols; ++i) { sum += getEntry(row, i) * v.getEntry(i); } out[row] = sum; } return new ArrayRealVector(out, false); } } /** {@inheritDoc} */ public double[] preMultiply(final double[] v) throws IllegalArgumentException { final int nRows = getRowDimension(); final int nCols = getColumnDimension(); if (v.length != nRows) { throw MathRuntimeException.createIllegalArgumentException( "vector length mismatch: got {0} but expected {1}", v.length, nRows); } final double[] out = new double[nCols]; for (int col = 0; col < nCols; ++col) { double sum = 0; for (int i = 0; i < nRows; ++i) { sum += getEntry(i, col) * v[i]; } out[col] = sum; } return out; } /** {@inheritDoc} */ public RealVector preMultiply(final RealVector v) throws IllegalArgumentException { try { return new ArrayRealVector(preMultiply(((ArrayRealVector) v).getDataRef()), false); } catch (ClassCastException cce) { final int nRows = getRowDimension(); final int nCols = getColumnDimension(); if (v.getDimension() != nRows) { throw MathRuntimeException.createIllegalArgumentException( "vector length mismatch: got {0} but expected {1}", v.getDimension(), nRows); } final double[] out = new double[nCols]; for (int col = 0; col < nCols; ++col) { double sum = 0; for (int i = 0; i < nRows; ++i) { sum += getEntry(i, col) * v.getEntry(i); } out[col] = sum; } return new ArrayRealVector(out); } } /** {@inheritDoc} */ public double walkInRowOrder(final RealMatrixChangingVisitor visitor) throws MatrixVisitorException { final int rows = getRowDimension(); final int columns = getColumnDimension(); visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int row = 0; row < rows; ++row) { for (int column = 0; column < columns; ++column) { final double oldValue = getEntry(row, column); final double newValue = visitor.visit(row, column, oldValue); setEntry(row, column, newValue

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> endRow, startColumn, endColumn); } /** {@inheritDoc} */ public double walkInOptimizedOrder(final RealMatrixPreservingVisitor visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException, MatrixVisitorException { return walkInRowOrder(visitor, startRow, endRow, startColumn, endColumn); } /** {@inheritDoc} */ @Deprecated public double[] solve(final double[] b) throws IllegalArgumentException, InvalidMatrixException { if (lu == null) { lu = new LUDecompositionImpl(this, MathUtils.SAFE_MIN).getSolver(); } return lu.solve(b); } /** {@inheritDoc} */ @Deprecated public RealMatrix solve(final RealMatrix b) throws IllegalArgumentException, InvalidMatrixException { if (lu == null) { lu = new LUDecompositionImpl(this, MathUtils.SAFE_MIN).getSolver(); } return lu.solve(b); } /** * Computes a new * <a href="http://www.math.gatech.edu/~bourbaki/math2601/Web-notes/2num.pdf"> * LU decomposition</a> for this matrix, storing the result for use by other methods. * <p> * <strong>Implementation Note</strong>:<br> * Uses <a href="http://www.damtp.cam.ac.uk/user/fdl/people/sd/lectures/nummeth98/linear.htm"> * Crout's algorithm</a>, with partial pivoting.</p> * <p> * <strong>Usage Note</strong>:<br> * This method should rarely be invoked directly. Its only use is * to force recomputation of the LU decomposition when changes have been * made to the underlying data using direct array references. Changes * made using setXxx methods will trigger recomputation when needed * automatically.</p> * * @throws InvalidMatrixException if the matrix is non-square or singular. * @deprecated as of release 2.0, replaced by {@link LUDecomposition} */ @Deprecated public void luDecompose() throws InvalidMatrixException { if (lu == null) { lu = new LUDecompositionImpl(this, MathUtils.SAFE_MIN).getSolver(); } } /** * Get a string representation for this matrix. * @return a string representation for this matrix */ @Override public String toString() { final int nRows = getRowDimension(); final int nCols = getColumnDimension(); final StringBuffer res = new StringBuffer(); String fullClassName = getClass().getName(); String shortClassName = fullClassName.substring(fullClassName.lastIndexOf('.') + 1); res.append(shortClassName).append("{"); for (int i = 0; i < nRows; ++i)

Math, 74

<FILEB>
<CHANGES>
final double[] scale = new double[y0.length];
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]);
}
<CHANGEE>
<CHANGES>
for (int i = 0; i < scale.length; ++i) {
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]);
}
<CHANGEE>
<FILEE>
<FILEB> stepStart = t0; double hNew = 0; boolean firstTime = true; for (StepHandler handler : stepHandlers) { handler.reset(); } CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop while (!lastStep) { interpolator.shift(); double error = 0; for (boolean loop = true; loop;) { if (firstTime || !fsal) { // first stage computeDerivatives(stepStart, y, yDotK[0]); } if (firstTime) { <CHANGES> final double[] scale; <CHANGEE> if (vecAbsoluteTolerance == null) { <CHANGES> scale = new double[y0.length]; java.util.Arrays.fill(scale, scalAbsoluteTolerance); <CHANGEE> } else { <CHANGES> scale = vecAbsoluteTolerance; <CHANGEE> } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; } stepSize = hNew; // next stages for (int k = 1; k < stages; ++k) { for (int j = 0; j < y0.length; ++j) { double sum = a[k-1][0] * yDotK[0][j]; for (int l = 1; l < k; ++l) { sum += a[k-1][l] * yDotK[l][j]; <FILEE> <SCANS> { if (i > 0) { res.append(","); } res.append("{"); for (int j = 0; j < nCols; ++j) { if (j > 0) { res.append(","); } res.append(getEntry(i, j)); } res.append("}"); } res.append("}"); return res.toString(); } /** * Returns true iff <code>object</code> is a * <code>RealMatrix</code> instance with the same dimensions as this * and all corresponding matrix entries are equal. * * @param object the object to test equality against. * @return true if object equals this */ @Override public boolean equals(final Object object) { if (object == this ) { return true; } if (object instanceof RealMatrix == false) { return false; } RealMatrix m = (RealMatrix) object; final int nRows = getRowDimension(); final int nCols = getColumnDimension(); if (m.getColumnDimension() != nCols || m.getRowDimension() != nRows) { return false; } for (int row = 0; row < nRows; ++row) { for (int col = 0; col < nCols; ++col) { if (getEntry(row, col) != m.getEntry(row, col)) { return false; } } } return true; } /** * Computes a hashcode for the matrix. * * @return hashcode for matrix */ @Override public int hashCode() { int ret = 7; final int nRows = getRowDimension(); final int nCols = getColumnDimension(); ret = ret * 31 + nRows; ret = ret * 31 + nCols; for (int row = 0; row < nRows; ++row) { for (int col = 0; col < nCols; ++col) { ret = ret * 31 + (11 * (row+1) + 17 * (col+1)) * MathUtils.hash(getEntry(row, col)); } } return ret; } }